Regular expressions

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • xoinki
    New Member
    • Apr 2007
    • 110

    Regular expressions

    I am trying to fetch "portal[portal] @ localhost [127.0.0.1]" info out of "User@Host: portal[portal] @ localhost [127.0.0.1]" I am trying to use negative lookahead for excluding user@host pattern.. like this, "(?!\\b(# User@Host: )\\b)\\b.*" but the problem is, the regex engine does not seem to work for a combination of a special character and a normal character.. if "@" is removed it works fine.. anybody experienced this sort of difficulty?? please help..thanks in Advance.. Xoinki
    Last edited by xoinki; May 7 '08, 12:23 PM. Reason: one string misssing
  • gpraghuram
    Recognized Expert Top Contributor
    • Mar 2007
    • 1275

    #2
    Originally posted by xoinki
    I am trying to fetch "portal[portal] @ localhost [127.0.0.1]" info out of "User@Host: portal[portal] @ localhost [127.0.0.1]" I am trying to use negative lookahead for excluding user@host pattern.. like this, "(?!\\b(# User@Host: )\\b)\\b.*" but the problem is, the regex engine does not seem to work for a combination of a special character and a normal character.. if "@" is removed it works fine.. anybody experienced this sort of difficulty?? please help..thanks in Advance.. Xoinki

    R u using any regex package or in which language u are trying to implement this?

    raghuram

    Comment

    • xoinki
      New Member
      • Apr 2007
      • 110

      #3
      hi,
      Thanks for d reply, I am using C++ and i am using PCRE(www.pcre.o rg), I found out another thing.. lets say the pattern to be matched is "@H portal[portal]@localhost" and the regex for extracting "portal[portal]@localhost" i would use "(?!@H).*" meaning: except @H match everything else.. this should match "portal[portal]@localhost" in theory but it is matching "H portal[portal]@localhost" so the combination of alphabets and special characters is causing the problem i found out! I am unable to findout whether this is a problem with PCRE or with my understanding and logic. looking for your help,
      Xoinki

      Comment

      • gpraghuram
        Recognized Expert Top Contributor
        • Mar 2007
        • 1275

        #4
        Originally posted by xoinki
        hi,
        Thanks for d reply, I am using C++ and i am using PCRE(www.pcre.o rg), I found out another thing.. lets say the pattern to be matched is "@H portal[portal]@localhost" and the regex for extracting "portal[portal]@localhost" i would use "(?!@H).*" meaning: except @H match everything else.. this should match "portal[portal]@localhost" in theory but it is matching "H portal[portal]@localhost" so the combination of alphabets and special characters is causing the problem i found out! I am unable to findout whether this is a problem with PCRE or with my understanding and logic. looking for your help,
        Xoinki
        I havent used pcre.
        I have used Lex to do similar type and i use to use [^ to negate matched patterns.

        Raghuram

        Comment

        • xoinki
          New Member
          • Apr 2007
          • 110

          #5
          [^ is used to negate character classes.. not strings..
          If we want to exclude strings then
          1) either we need to use negative lookahead as i am trying.
          2) or replace the not required pattern.
          3) or just use pure C++.

          I am trying with 1 not yet went for 2 and 3.. PCRE is same as any other regex..

          thnx for replying,
          Xoinki

          Comment

          Working...