-1

Language: C#

I am confused as to the meaning of the following regex I found in my code base:

\A\b[0-9a-fA-F]+\b\Z

Demo at regexr.com

  1. Regarding the \b: I see A32131Z dasdaA3123Z312 would be matches if \b would be replaced by \B (meaning, matching A being boundary to a word character). I am having trouble to figure out a match for the original regex. \b means A should be followed by a non word character, which will never be the case for [0-9a-fA-F]+ ? And in case this means that A is expected to be followed by a non word character, and then by any of [0-9a-fA-F]+, then why are A 287FA Z or A_287FA!Z not a match ?

  2. could not \A and \Z be replaced simply A and Z ?

Bottom line, I am wondering if this regex does ever generate a match, in its original form (\b).

Veverke
  • 5,705
  • 2
  • 43
  • 86
  • `\A` - start of string, `\Z` - end of string. `\b` are irrelevant in this regex as it only matches hex digit (word) chars. – Wiktor Stribiżew May 08 '22 at 20:51
  • @WiktorStribiżew: Is there a match for \A\b[0-9a-fA-F]+\b\Z ? Is it not a problem the fact that \b is followed by the hexa chars specification ? In other words regex expects at the same time that A should be followed by hexa chars AND that A should be followed by a non-word character, and these 2 conditions will never be true together ?! – Veverke May 08 '22 at 20:53
  • Again, `\A` means assert start of string, it doesn't mean match `A`. Try `"123"` for example at [http://regexstorm.net](http://regexstorm.net/tester). The `\b` are unnecessary because the start and end of string are already word boundaries. – MikeM May 08 '22 at 21:02
  • See https://regex101.com/r/QAy2vj/1. See the explanation on the right. `\b` can be removed, they are irrelevant - in this regex. – Wiktor Stribiżew May 08 '22 at 21:05

0 Answers0