Got more questions? Find advice on: ASP | SQL | XML | Windows
Welcome to RegexAdvice Sign in | Join | Help

Backreference in square brackets

  •  07-24-2007, 11:17 AM

    Backreference in square brackets

    String: cxaaz0a9mmm

    Pattern ([ab])\1 returns 1 match aa

    Pattern ([ab])[\1] returns no mathches (expected: as above)

    Pattern ([ab])[^\1] returns 2 matches aa and a9 (expected and wanted: 1 match a9)

    Please

    1. explain why single-character backreference does not work as expected [by myself :-( ] and
    2. give me recommendation how to match a single (not doubled one) captured character referred with backreference \1. (Two characters, the first being  "a" or "b" and the second character defferent from the first).

    Thanks

    Filed under:
View Complete Thread