Menu

problem with special pattern

Help
2003-03-31
2003-04-10
  • Nobody/Anonymous

    Hi,

    I've a list of strings which contain substrings like this:

    ABC, XYZ,PR1,PR12,aPR1,PR23a,...

    I want to find only PR1,PR12.
    The pattern should be : \<PR\d{1,2}[^a-zA-Z]*
    But PR23a is also in the list. Why?
    thx,
    Oliver

     
    • Sergey A. Samokhodkin

      I couldn't find any problem with it.
      Matching

      \<PR\d{1,2}[^a-zA-Z]*

      against the string

      ABC, XYZ,PR1,PR12,aPR1,PR23a,...

      I get the correct matches: "PR1," , "PR12," and  "PR23". The last one is in the list because it
      indeed starts with "PR", has "1 to 2 digits", and ends with "zero or more non-letters" (actually zero).

      Wild guess: may be you need to insert the "word end" mark after digits:

      \<PR\d{1,2}\>[^a-zA-Z]*

      In that case you get only "PR1," and "PR12,".

      Does it help?

       

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.