- Code: Select all
([a-zA-Z]+) captures one or more letters into group 1, provided they are also followed by space(s) or a word-break.
(?:(\s+?)|\b) is a non-capturing group, but if there are one or more spaces these are
captured into a group, 2.
The ? following \s+ is necessary to create a non-greedy capture, otherwise the 'g' modifier will possibly force a capture of the whole line in one go!
?1: is a conditional, which says 'if anything was captured in group 1', insert this..
(?2:-) is a nested-conditional, and it will be ignored if there was no capture for group 2.
(?2:-:Doh) would (two colons : ) extend the conditional to say: "if group 2 was captured, insert a hyphen, otherwise insert 'Doh'".
PS I didn't know there was any such thing as a 'nested conditional' either - I just tried it
"I'm here to save your life. But if I'm going to do that, I'll need total uninanonynymity." Me Myself & Irene.