Simplifying a regular expression using backreferences

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • TenTen
    New Member
    • Sep 2007
    • 3

    Simplifying a regular expression using backreferences

    hi, I'm a regex beginer and I want to know if with backreferences \1 I can reduce the ip test regex that I found on a web site :
    Code:
    \b (25[0-5] |2 [0-4] [0-9]| [01]? [0-9][0-9]?)\. (25[0-5] |2 [0-4] [0-9]| [01]? [0-9][0-9]?)\. (25[0-5] |2 [0-4] [0-9]| [01]? [0-9][0-9]?)\. (25[0-5] |2 [0-4] [0-9]| [01]? [0-9][0-9]?)\b
    By something like that :
    Code:
     \b (25[0-5] |2 [0-4] [0-9]| [01]? [0-9][0-9]?)\.)\1\1 (25[0-5] |2 [0-4] [0-9]| [01]? [0-9][0-9]?)\b?
    I ask that in aim of understand backreferences thank you for answer me.

    (@^_^@)
  • pbmods
    Recognized Expert Expert
    • Apr 2007
    • 5821

    #2
    Heya, Ten. Welcome to TSDN!

    Please use CODE tags when posting source code:

    [CODE]
    Source code goes here.
    [/CODE]

    Comment

    • TenTen
      New Member
      • Sep 2007
      • 3

      #3
      ok, sorry for that ...

      Comment

      • pbmods
        Recognized Expert Expert
        • Apr 2007
        • 5821

        #4
        Heya, Ten.

        That should work, assuming that you want the first three octets to be identical. Backreferences match the result of the rule, not the rule itself.

        Comment

        • TenTen
          New Member
          • Sep 2007
          • 3

          #5
          ok if I understand exactly what you say, if the first octet is 175 with backreference the second and third term are 175 too ...

          this is not what I want but at this time backreference were easier now

          thank you for the help

          cya

          Comment

          Working...