#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Dec 2009
    Posts
    11
    Rep Power
    0

    Problem with regex


    Hello,

    Can someone help me figure out why this regex isn't working?

    re.search('([\.]+)([F][0-9]{1,5}[S][0-9]{1,5}+)','application.F123.S123', re.IGNORECASE)

    It is supposed to return a match of '.F123.S123' but it keeps erroring out. the 1,5 is required though as someones the numbers are between 1-5, the strings are also significantly long hence the F and S matches.

    Odd thing is this works fine with the online regex tester:
    http://gskinner.com/RegExr/

    Just not in python.
  2. #2
  3. Did you steal it?
    Devshed Supreme Being (6500+ posts)

    Join Date
    Mar 2007
    Location
    Washington, USA
    Posts
    13,988
    Rep Power
    9397
    1. What error?
    2. Your expression doesn't account for the . between the F123 and the S123.
  4. #3
  5. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Dec 2009
    Posts
    11
    Rep Power
    0
    Hello,

    I think I figured it out:

    (\.\F\d{1,5}\S\d{1,5})

    The error was "sre_constants.error: multiple repeat" so did a ton of Googling and eventually rewrote the regex, I learned a lot about it today!
  6. #4
  7. Did you steal it?
    Devshed Supreme Being (6500+ posts)

    Join Date
    Mar 2007
    Location
    Washington, USA
    Posts
    13,988
    Rep Power
    9397
    Code:
    {1,5}+
    is valid in a bunch of languages: apparently Python isn't one of them.

    (I actually wondered about that, but I figured Python was developed enough to support that kind of greedyness.)
  8. #5
  9. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Dec 2009
    Posts
    11
    Rep Power
    0
    indeed, took me a while of debugging to figure out the greed + was the problem

IMN logo majestic logo threadwatch logo seochat tools logo