Breaking the regex down to its components we have:
N
and :
are just literals. Nothing to say about those.
\b
is the word boundary pseudo class. It will match either the beginning of the string, its end, or a word boundary. A word boundary is the beginning or end of a word. This is a bit weird because it matches ("consumes") no characters. In the string "foo bar" there are 4 word boundaries (before f, after o, before b, after r).
A *
means that the previous match can be repeated any number of times (0, 1, 2 or more). This means you're accepting any number of consecutive word boundaries.
Finally the brackets [
]
define a class. Inside this class there is ^:
. The ^
means "inverse". For example if you have a class [a]
it will match the character a
. But [^a]
will match everything except a
. So the class [^:]
will match everything except :
. Finally we have a *
again meaning you can match this class any number of times.
So putting everything together here's what the regex means:
- match the letter
N
- match any number of word boundaries
- match the character
:
- match any number of word boundaries
- match any number of characters except
:
.
Here are a few examples:
N:
- matches, it's the simplest match
N
- doesn't match, there's no :
N:foobar
- matches
N:foobar:baz
- doesn't match, the second :
is not allowed.
This whole word boundaries business is not very intuitive and it isn't clear without context what is meant here. Matching word boundaries around the :
doesn't make much sense. But at least you should be able to understand the regex better already.