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

    Join Date
    Jul 2011
    Posts
    3
    Rep Power
    0

    Regex for unknown order


    In my example I have receive two rows of data and I need to know which row contains the "RFA" record. Now the problem is that the order can be different every time. So I'm having trouble getting a regex working that will return me the _afrRK value. The ellipse '...' in the examples means that there is extra text between the data.

    Code:
    <tr _afrRK="0" class="af_table_data-row"><td  ... Modification Request - RFA - #B000110051 from
    <tr _afrRK="1" class="af_table_data-row"><td  ... Modification Request - FYI - #B000110051 has been
    The RFA row key for the first one is "0".

    Code:
    <tr _afrRK="0" class="af_table_data-row"><td  ... Modification Request - FYI - #B000110051 has been
    <tr _afrRK="1" class="af_table_data-row"><td  ... Modification Request - RFA - #B000110051 from
    The RFA row key for this is "1".

    Thanks,

    Matt D.
  2. #2
  3. Transforming Moderator
    Devshed Supreme Being (6500+ posts)

    Join Date
    Mar 2007
    Location
    Washington, USA
    Posts
    14,129
    Rep Power
    9398
    I'd use half-regex, half-regular-string-stuff. With
    Code:
    <tr _afrRK="(\d+)".*?</tr>
    you can grab each <tr> (and row key). Then check each one for a "Modification Request - RFA".

    What programming language are you using?
  4. #3
  5. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2011
    Posts
    3
    Rep Power
    0
    Originally Posted by requinix
    I'd use half-regex, half-regular-string-stuff. With
    Code:
    <tr _afrRK="(\d+)".*?</tr>
    you can grab each <tr> (and row key). Then check each one for a "Modification Request - RFA".

    What programming language are you using?
    Thanks for the quick response, I'm using Perl. Wouldn't the regex above get both instances because it would terminate at the second </tr> tag?

    Matt
  6. #4
  7. Transforming Moderator
    Devshed Supreme Being (6500+ posts)

    Join Date
    Mar 2007
    Location
    Washington, USA
    Posts
    14,129
    Rep Power
    9398
    The ? in .*? makes it ungreedy, which means Perl will match as few characters as possible. It'll terminate at the earliest opportunity: the first ending tag.
  8. #5
  9. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2011
    Posts
    3
    Rep Power
    0
    Gotcha, thanks that got me where I needed to go along with some string checking like you said.

IMN logo majestic logo threadwatch logo seochat tools logo