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:
https://regex101.com/
https://www.regextester.com
https://www.analyticsmarket.com/freetools/regex-tester/
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?
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:
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.
Related
The following combinations should be covered by this regex:
test-ds-s**
test-s**
test-d**
(** two numbers from 0-9)
My regex looks like this: ^test-(ds-)?[ds]\\d{2,2}$
But now test-ds-d** is also possible, what I dont want. Is there any way to make the d only possible, when the optional ds- part is not used?
You can use
^test-(ds-(?!d))?[ds]\d{2}$
See the regex demo.
Details
^ - start of string
test- - a fixed string
(ds-(?!d))? - an optional capturing group matching ds- if not immediately followed with d
[ds] - d or s
\d{2} - two digits
$ - end of string.
For strings like Cisco 3750 i7706-cm021 10.123.12.34 -> 10.123.34.12 I would like to get result Cisco 3750 i7706-cm021 10.123.12.34 -> using expression ^.*(?![\d\.]{12}$). But instead a whole string is matched. What is the correct expression would be?
You may use a regex like
^.*?(?=\b(?:\d{1,3}\.){3}\d{1,3}$)
See the regex demo and the Regulex graph:
Details
^ - start of string
.*? - any 0+ chars other than line break chars, as few as possible
(?=\b(?:\d{1,3}\.){3}\d{1,3}$) - a positive lookahead that requires (immediately to the right of the current location):
\b - word boundary
(?:\d{1,3}\.){3} - three repetitions of 1 to 3 digits and a dot
\d{1,3} - one to three digits
$ - end of string.
To get more precise IP regex, see How to Find or Validate an IP Address:
^.*?(?=\b(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)$)
See the regex demo
^([-+]?)([\d]{1,2})(((\.)(\d+)(,)))(([-+]?)([\d]{1,3})((\.)(\d+))?)$
I am trying to use this regex above to be able to confirm that the data is a valid coordinate. I am having trouble getting this to work with Firebase rules. When i run the regex in an online regex tester, it works okay, but Firebase rules doesn't seem to accept it.
Here is my firebase rule:
".validate": "newData.isString() && newData.val().matches(/^([-+]?)([\d]{1,2})(((\.)(\d+)(,)))(([-+]?)([\d]{1,3})((\.)(\d+))?)$/)"
Is there anyway to get this working?
You need to double the escaping backslashes, but honestly, your expression contains too many redundant grouping constructs.
Use
.matches(/^[-+]?\\d{1,2}\\.\\d+,[-+]?\\d{1,3}(\\.\\d+)?$/)
or avoid the backslashes altogether:
.matches(/^[-+]?[0-9]{1,2}[.][0-9]+,[-+]?[0-9]{1,3}([.][0-9]+)?$/)
The regex will match strings like in this online demo.
Details:
^ - start of string (in Firebase regex, it is an anchor when used at the start of the pattern only)
[-+]? - 1 or 0 + or -
[0-9]{1,2} - 1 or 2 digits
[.] - a dot
[0-9]+ - 1+ digits
, - a comma
[-+]? - 1 or 0 + or -
[0-9]{1,3} - 1 to 3 digits
([.][0-9]+)? - 1 or 0 sequences of . and 1+ digits (note that non-capturing groups are not supported)
$ - end of string anchor (only when at the pattern end, $ matches the end of string in Firebase regex).
I'm having issues with the validation of the chilean RUT/RUN with a regex expression in PCRE. I have the next regular expression but sadly can't make it work:
\b[0-9|.]{1,10}\-[K|k|0-9]
I need help to see what is wrong with the code. The application I need to use only uses PCRE.
Thank you.
You may use
^(\d{1,3}(?:\.\d{1,3}){2}-[\dkK])$
to match and capture (that is not usually necessary, but your app requires a capturing group to extract its contents) a whole string that matches the pattern. See the regex demo.
To match shorter strings that match this pattern inside a larger string, you may remove ^ and $ (see demo) or use \b word boundaries instead (see this demo).
Details:
^ - start of string
\d{1,3} - 1 to 3 digits
(?:\.\d{1,3}){2} - 2 sequences of a literal . and 1 to 3 digits
- - a hyphen
[\dkK] - a digit, k or K.
$ - end of string.
As they sometimes omit the dots, I used this one:
^(\d{1,2}(?:[\.]?\d{3}){2}-[\dkK])$
Details:
^ - start of string
\d{1,2} - 1 or 2 digits
(?:[.]?\d{3}){2} - 2 sequences of an optional '.' and 3 digits
- a hyphen
[\dkK] - a digit, k or K
$ - end of string
1234567-k OK
12345678-k OK
1.234.567-k OK
12.345.678-k OK
known issue:
12.345678-k and 12345.678-k still OK and I do not like this :(
You need to change to ^(\d{1,3}(?:\.\d{3}){2}-[\dkK])$ to capture only 2 sequence of 3 digits after the first sequence of 1-3 digits.
please consider being more specific in the REGEX build, since it matched wrong numbers, such as 17.87.335-2. Also the included one did't match formats without the dots or the hyphens.
Please consider using the following format: \b(\d{1,3}(?:(.?)\d{3}){2}(-?)[\dkK])\b
Modified prior version to try the other formats: https://regex101.com/r/2Us0j6/9
^([-+]?)([\d]{1,2})(((\.)(\d+)(,)))(([-+]?)([\d]{1,3})((\.)(\d+))?)$
I am trying to use this regex above to be able to confirm that the data is a valid coordinate. I am having trouble getting this to work with Firebase rules. When i run the regex in an online regex tester, it works okay, but Firebase rules doesn't seem to accept it.
Here is my firebase rule:
".validate": "newData.isString() && newData.val().matches(/^([-+]?)([\d]{1,2})(((\.)(\d+)(,)))(([-+]?)([\d]{1,3})((\.)(\d+))?)$/)"
Is there anyway to get this working?
You need to double the escaping backslashes, but honestly, your expression contains too many redundant grouping constructs.
Use
.matches(/^[-+]?\\d{1,2}\\.\\d+,[-+]?\\d{1,3}(\\.\\d+)?$/)
or avoid the backslashes altogether:
.matches(/^[-+]?[0-9]{1,2}[.][0-9]+,[-+]?[0-9]{1,3}([.][0-9]+)?$/)
The regex will match strings like in this online demo.
Details:
^ - start of string (in Firebase regex, it is an anchor when used at the start of the pattern only)
[-+]? - 1 or 0 + or -
[0-9]{1,2} - 1 or 2 digits
[.] - a dot
[0-9]+ - 1+ digits
, - a comma
[-+]? - 1 or 0 + or -
[0-9]{1,3} - 1 to 3 digits
([.][0-9]+)? - 1 or 0 sequences of . and 1+ digits (note that non-capturing groups are not supported)
$ - end of string anchor (only when at the pattern end, $ matches the end of string in Firebase regex).