CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2
  1. #1
    Join Date
    Sep 2006
    Posts
    28

    perl regular expession

    How do I have my php match the following:
    "<key1></key1>" but not "<key1></key2>"
    Basically I have the following:
    "<key1>Something inside here</key1><key2>Something inside here</key2>", and so my preg looks like this:
    Code:
    if ( !preg_match("/(<key\d+>.*?<\/key\d+>|)+/,$variable) )
    {
      $error = true;
    }
    But it would be cool to check to see if its incremented like 1...2...3 and to see if they are the same.

  2. #2

    Re: perl regular expession

    I'm not sure about PHP but in Perl you'd use backreferences. For example, you can do something like:

    /(<(key\d+)>.*?<\/$2>|)+/

    In other words, you're creating a second capture group around the around the key entry and looking for the output of that same capture group in an adjacent tag.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured