-2

Can anyone tell me what this kind of Regular Expression is doing?

(\s*(\s*#\s*(?\d+)\s*))

If I test it an add whitespaces it says there is no match.

Can somebody give me an example? :)

oleksii
  • 33,544
  • 11
  • 83
  • 149
KrAyZiE CS
  • 13
  • 3
  • 3
    use any online regex tool, you will have a full explanation on the right side https://regex101.com/r/xb7TTb/1 , https://regexr.com/5ov6o – Self Mar 19 '21 at 13:24
  • 4
    Does this answer your question? [Reference - What does this regex mean?](https://stackoverflow.com/questions/22937618/reference-what-does-this-regex-mean) – Self Mar 19 '21 at 13:26
  • 1
    Seems there was an error in the regular expression, which was then edited (not by OP) to a valid regex. I've reverted the edit, in case OP wonders why there are two different regexes now: original and [the edited one](https://regex101.com/r/xb7TTb/1) – oleksii Mar 19 '21 at 13:29
  • Your regular expression is not correct. try this ```(\s*(\s*#\s*(\d+)\s*))``` – MD. RAKIB HASAN Mar 19 '21 at 13:36

1 Answers1

0

That regular expression is not correct. Try removing the ? character.

(\s*(\s*#\s*(\d+)\s*))

And this expression matches any number that has an # in front of it. For example, in the next lines, it matches lines 1,2,5 and 6.

  #995
#995
  995
995
#995 9
  #654 233
233

You can test it in the following link: http://regexstorm.net/tester?p=%28%5cs*%28%5cs*%23%5cs*%28%5cd%2b%29%5cs*%29%29&i=++%23995%0d%0a%23995%0d%0a++995%0d%0a995%0d%0a%23995+9%0d%0a++%23654+233%0d%0a233