12

I'm looking for a regular expression tester for Google Big Data (RE2) reg expressions. There are a few testers out there, but none of them seems to understand my statement. These are the ones I've tried and they've worked for simple expressions but not with mine:

This is my regex:

^(?:1-)?((?:R|RO|Ro)?[:|.]?\\s?\\d{3}[-|.]?\\d{4}[-|/]F\\d{2}-\\d{2})$

where I would process strings like these:

  • Ro 708-2859/F07-01
  • RO708-2859-F06-04
  • RO703-3877-F01
  • 1-RO520-0628-F08
  • RO6868847-000-010

Does anyone have an idea of how I might enter the statement different or where I could test it?

Mikhail Berlyant
  • 165,386
  • 8
  • 154
  • 230
devnull
  • 131
  • 1
  • 1
  • 5

2 Answers2

4

You can use

^(?:1-)?((?:R[Oo]?)?[:.]?\s?\d{3}[-.]?\d{4}[-/](?:F\d{2}(?:-\d{2})?|\d{3}[-/]\d{3}))$

See the regex demo. Details:

  • ^ - start of string
  • (?:1-)? - an optional 1- string
  • ((?:R[Oo]?)?[:.]?\s?\d{3}[-.]?\d{4}[-/](?:F\d{2}(?:-\d{2})?|\d{3}[-/]\d{3})) - Group 1:
    • (?:R[Oo]?)? - an optional sequence of R and then an optional O or o
    • [:.]? - an optional : or .
    • \s? - an optional whitespace
    • \d{3} - three digits
    • [-.]? - an optional - or .
    • \d{4} - four digits
    • [-/] - - or /
    • (?:F\d{2}(?:-\d{2})?|\d{3}[-/]\d{3}) - either F, two digits and then an optional sequence of - and two digits, or three digits, - or / and three digits
  • $ - end of string.

See the Google Sheets demo:

enter image description here

Wiktor Stribiżew
  • 607,720
  • 39
  • 448
  • 563
1

You may try to use https://www.regexplanet.com/advanced/golang/index.html

I've tried your regexp, and this also pointing to Re2 for docs.

Hubbitus
  • 5,161
  • 3
  • 41
  • 47