Home > Mobile >  Regex - Extract string between characters if they exist
Regex - Extract string between characters if they exist

Time:06-17

I would need to use RegEx to extract a string between characters if they exist (The colon character).

Examples:

  • SX: 22AA 001 267
  • 2294 0BB 267: 09
  • 2294 0CC 267

In all cases, I want the result.

2294 001 267

Thank you all.

CodePudding user response:

You can use this regex to match them all

(?:^|:)\s?([A-Z\d] (?: [A-Z\d] ) )(?:$|:)

NOTE: As you did not mention what language you're using I decided to not use lookarounds. So you have to get the first group from the match.

  • Related