Menu

finding the next match

Help
2003-09-02
2003-09-05
  • saktheesh p

    saktheesh p - 2003-09-02

    my problem is that i have a strings of regular expression seperated by '|'

    and if i have a regular expression of a sort like
    .... ([0-9]{2}-[0-9]{2}-[0-9]{2}(-[0-9]{2})?)|([0-9]{2}(\-[0-9]{2}){2}(\-[0-9]{3,5}){2})|..

    and if i have a string like "21-31-51-000-002" jregex finds the match only with the first regular expession and gives the match result as "21-31-51-0" and not the actual result "21-31-51-000-002" that should match with the second regular expression is there any way to do this

     
    • Sergey A. Samokhodkin

      Hello, saktheesh_p!

      That is the normal behaviour for Perl-style regex engines.
      If the 1-st '|'-separated alternative matches, no others are tried for the longer match.

      That are the POSIX-style regexes that search for globally longest match.

      Cheers

       
      • saktheesh p

        saktheesh p - 2003-09-05

        is there any way that i can make the jregex get the longest match

         
        • Sergey A. Samokhodkin

          Jregex is a Perl-style regex engine, so there isn't.

          That is the cost we pay for rich functionality.
          The POSIX regular expressions don't have such things as look-arounds, anchors, unicode support, and may be something else.

          The only truly POSIX decent RE engine I know of is the ...awk.* part of the Jakarta-ORO.

          Regards

           
          • Sergey A. Samokhodkin

            I've got an idea.
            You can use the proceed() method to get all possible matches at a particular place.

             

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.