Advanced Regular Expressions - Mission 369-6

Hey guys, I am bit confused with this word boundary character (\b).

Screen Link:
I want to know the difference between

\b(a)\b\1

and

\b(a)\b\s\1

I though first pattern should match a a but it doesn’t and the second pattern actually matches the string a a.

Is it the case that \b just checks if word char is not followed by non-word char and rather than matching with whats been followed

\b is a zero-length match. It will not consume the space, so \s in your 2nd pattern is required to get a a.

You can use https://regex101.com/ to interactively learn what is going on by

  1. Editting the regex while keeping string constant
  2. Editting the string while keeping regex constant

Look at the “MATCH INFORMATION” panel on the right, and mouseover the annotated string (after matching) to see where every item in the match output appears in the string.

1 Like

Got it, I was thinking in the same way, but the implementation clears it up.