Java Regex 2 - Duplicate Words

  • + 0 comments

    No, unfortunately.

    Java Strings use the backslash as an escape character, as do regular expressions.

    This is why regular expressions look so messy when using shorthands for word characters (\w) etc. We mean "\w" but we need to write "\\w" in Java as the first backslash is the escape character, and the second backslash tells it we actually mean a backslash.

    Internally, only a single backslash is used so "\\w" written in your code actually is stored as "\w" and is used as such in regular expressions.

    I hope this helps - although it may disappoint!