backreference
Notepad++ Regex Backreference syntax in Search/Replace – \1 or $1
Notepad++’s earlier versions (v5.9.8 and prior) only supported standard POSIX Regular Expressions. However, full PCRE (Perl Compatible Regular Expression) Search/Replace support was added in version 6.0: New features and enhancement in Notepad++ 6.0: PCRE (Perl Compatible Regular Expressions) is supported. This means that if you’re using Notepad++ v6.0 or any newer version (e.g v6.1.5), you … Read more
Backreferences Syntax in Replacement Strings (Why Dollar Sign?)
Is the use of $ for backreferences in replacement strings unique to Java? No. Perl uses it, and Perl certainly predates Java’s Pattern class. Java’s regex support is explicitly described in terms of Perl regexes. For example: http://perldoc.perl.org/perlrequick.html#Search-and-replace Why is this a good idea? Well obviously you don’t think it is a good idea! But … Read more
Negating a backreference in Regular Expressions
Instead of a negated character class, you have to use a negative lookahead: \bvalue\s*=\s*([“‘])(?:(?!\1).)*\1 (?:(?!\1).)* consumes one character at a time, after the lookahead has confirmed that the character is not whatever was matched by the capturing group, ([“”]). A character class, negated or not, can only match one character at a time. As far … Read more
JavaScript – string regex backreferences
Like this: str.replace(regex, function(match, $1, $2, offset, original) { return someFunc($2); })
Regular expression for duplicate words
Try this regular expression: \b(\w+)\s+\1\b Here \b is a word boundary and \1 references the captured match of the first group. Regex101 example here