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

    Join Date
    May 2019
    Posts
    5
    Rep Power
    0

    Splitting a regex match


    Hi everyone, my name is Mitch and I am a Year 12 Software Development student in Australia.

    I have encountered a problem when testing a regular expression against a pager message string.
    I am trying to match 1 or more fire brigade codes (CBAGR, CBORT, etc.). I have matched 3 brigade codes
    into one match and the last brigade is its own match.

    Is there a way I can split each individual brigade code (CBAGR, CBORT, etc.) into a single match. The link
    to the regex is here. Thank you very much for your help.

    Regards,

    Mitch
  2. #2
  3. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    May 2019
    Posts
    5
    Rep Power
    0
    Sorry, I am unsure how to edit the post. The new link to the regex is here
  4. #3
  5. Headless Moderator
    Devshed Supreme Being (6500+ posts)

    Join Date
    Mar 2007
    Location
    Washington, USA
    Posts
    16,967
    Rep Power
    9647
    It depends on the tool/language you're using to run this regular expression. Some allow for retrieving all the values matched by a single group, some don't.

    So. What tool or language?
  6. #4
  7. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    May 2019
    Posts
    5
    Rep Power
    0
    Hi requinix,

    Thanks for the reply. I am using PHP to run the expression. Thank you
  8. #5
  9. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    May 2019
    Posts
    5
    Rep Power
    0
    Sorry for all of the posts, I haven't used the right terminology. I am very new to this sorry. I wanted to match each of the brigade codes into a separate group, not a separate match.

    https://regex101.com/r/HMHifc/3

    Sorry again.
  10. #6
  11. Headless Moderator
    Devshed Supreme Being (6500+ posts)

    Join Date
    Mar 2007
    Location
    Washington, USA
    Posts
    16,967
    Rep Power
    9647
    The only way is if you write the codes directly into the regex, which I'm not sure you can do.
    Code:
    \s(((CBAGR)|(CYAND)|(CBORT)|(CKERA))\s)+
    Tip: start using named groups so you don't have to count parentheses.

    If not then you need the original regex to match all the codes at once, then something else (like explode on spaces) to get the individual codes.
  12. #7
  13. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    May 2019
    Posts
    5
    Rep Power
    0
    Thank you very much again requinox!

    I may just do what you said and capture all of the codes and then use explode to grab each code. Thanks again

IMN logo majestic logo threadwatch logo seochat tools logo