News for hackers. Stuff that matters.
Re:Anic - Faster than C, Safer than Java, Simpler than *sh by btilly on Tuesday August 14, 2012 @07:32PM (#4383615)
What you use depends on where you use it. Inside of a match, \1 refers to what was matched by the first parens. After the match $1 refers to what was matched. In a substitution, \1 is special cased to mean $1, but that is frowned on.

Thus: /\b(\w+)\W+\1\b/ means "match repeated word".

And: /\b(\w+)\W+$1\b/ means "match word preceeded by the word matched on your last match.

Moving on: s/Hello (\w+)/Goodbye $!/ means "Replace Hello followed by a word with Goodbye followed by the same word."

And finally: s/Hello (\w+)/Goodbye \1/ is special cased to mean the same thing, but is frowned upon.

There are no comments on this comment yet.