^ represents beginning of string
([^\-]+)
parentheses makes group of characters
square brackets represents inclusive any characters inside.
when "^" used inside, it is opposite (exception)
\- represents hyphen, it needs to be escaped by forward slush as - is a metacharacter.
+ represents one or more.
so, ^([^\-]+) means group of character(s) that exclude hyphen from the beginning.
?
a space means a space itself and ? represents one or none.
So it means with/without space
([A-Z]+( ([A-Z]+)(?!\d))*)\b.*
This one is a bit tricky and the key of this pattern.
[A-Z]+ means any character(s) between A to Z
( ([A-Z]+)(?!\d))*
* represents none or many
when ? used with open round brackets, it excludes from backward reference. (talk about this later)
and when ?! used with open round brackets, it is a negative match, means the characters that doesn't follow the character(s) specified.
\d represents number.
So it means one or more character(s) of A to Z and none or may of the string that have a space with A to Z that doesn't have numbers followed.
.*
Period represents any character, so it is simply none or many of any characters.
Backward reference
You can retrieve any submatches within a pattern via index of open round brackets EXCEPT those with "?".
So, ^([^\-]+) will be $1, dollar sign should be used with Replace method and the index starts from 1 and it only can refer up to 9.
But when referencing Submatches collection from Execute method, index starts from 0.
(it is not used in your case, so just for the information)
Google the net and you will find many good sites explaining this, though only a few can be found for the information regarding negative match....
Good luck.
Bookmarks