I want a Regex for version that accepts this format:
##.##.##
====
but that doesn't accept
00.00.00
If your regex dialect supports negative lookahead assertions (?!...) this is easy:
^(?!00\.00\.00$)(\d{2}\.){2}\d{2}$
If your regex dialect does not support ?! and/or \d, please update your question with pertinent details and/or tags.
If only 00.00.00 is not acceptable, then you can use the following regex
00\.00\.(?:0[1-9]|[1-9]\d)|00\.(?:0[1-9]|[1-9]\d)\.\d{2}|(?:0[1-9]|[1-9]\d)\.\d{2}\.\d{2}
A regular expression could look like this:
(0[1-9]|[1-9]\d)\.(0[1-9]|[1-9]\d)\.(0[1-9]|[1-9]\d)
(\d is a digit, \. is a dot, [1-9] is a digit from 1 to 9)
explanation in detail:
0[1-9] will match numbers from 01 to 09
[1-9]\d will match 10 to 99
(0[1-9]|[1-9\d) will match either 01 to 09 or 10 to 99 (so any number from 01 to 99)
these will be accepted:
01.01.01
11.11.11
55.55.55
55.01.33
10.20.30
these will not be a match:
00.01.01
00.00.00
44.33.00
http://regex101.com/r/lE7uH6
Related
I want to match everything between "02A1" and "03" IF its 14 characters in between those two.
My RegEx Pattern looks like this:
(02A1)[0-9A-Z]{14}(03)
My problem: It also matches this:
02A103EEFFFFF702A103
What am i doing wrong? "EEFFFFF7" is clearly not between 02A1 und 03 as before the EEFFFFF7 theres a 03 and after it theres a 02A1.
Can someone help me?
If the fourteen alphanumeric chars cannot contain a 03 substring, use
02A1(?:(?!03)[0-9A-Z]){14}03
If it cannot contain 02A1 either, use
02A1(?:(?!03|02A1)[0-9A-Z]){14}03
See this regex demo.
Details:
02A1 - a 02A1 string
(?:(?!03|02A1)[0-9A-Z]){14} - fourteen occurrences of an uppercase ASCII letter or digit that does not start a 03 or 02A1 char sequence
03 - a 03 string.
I have a regex
\(?\+\(?49?\)?[ ()]?([- ()]?\d[- ()]?){11}
This correctly matches German phone code like
+491739341284
+49 1739341284
(+49) 1739341284
+49 17 39 34 12 84
+49 (1739) 34 12 84
+(49) (1739) 34 12 84
+49 (1739) 34-12-84
but fails to match 0049 (1739) 34-12-84.
I need to adjust the regular expression so that it can match numbers with 0049 as well. can anyone help me with the regex?
Try this one:
\(?\+|0{0,2}\(?49\)?[ ()]*[ \d]+[ ()]*[ -]*\d{2}[ -]*\d{2}[ -]*\d{2}
https://regex101.com/r/CHjNBV/1
However, it's better to make it accept only +49 or 0049, and throw the error message in case the number fails validation. Because if someday you will require to extend the format - it will require making the regex much more complicated.
If you want to match the variations in the question, you might use a pattern like:
^(?:\+?(?:00)?(?:49|\(49\))|\(\+49\))(?: *\(\d{4}\)|(?: ?\d){4})? *\d\d(?:[ -]?\d\d){2}$
Explanation
^ Start of string
(?: Non capture group
\+? Match an optional +
(?:00)? Optionally match 2 zeroes
(?:49|\(49\)) Match 49 or (49)
| Or
\(\+49\) Match (+49)
) Close non capture gruop
(?: Non capture group
* Match optional spaces
\(\d{4}\) Match ( 4 digits and )
| Or
(?: ?\d){4} Repeat 4 times matching an optional space and a digit
)? Close non capture group and make it optional
* Match optional spaces
\d\d Match 2 digits
(?:[ -]?\d\d){2} Repeat 2 times matching either a space or - followed by 2 digits
$ End of string
Regex demo
Or a bit broader variation matching the 49 prefix variants, followed by matching 10 digits allowing optional repetitions of what is in the character class [ ()-]* in between the digits.
^(?:\+?(?:00)?(?:49|\(49\))|\(\+49\))(?:[ ()-]*\d){10}$
Regex demo
I want to extract the mobile phones from candidates' CVs.
The mobile phone format I want to extract is 69xxxxxxxx.
The mobile phone formats i come across in the CVs are:
69 xxx xxxxx
0030 69xxxxxxxx
+3069xxxxxxxx
69/xxxx/xxxx
The following formula works great but it extracts the first 10 digits detected and not the one that starts with 69.
=IFERROR(REGEXEXTRACT(TO_TEXT(SPLIT(REGEXREPLACE(I252;"\(|\)|\-| "; ""); CHAR(10))); "\d{10}"))
You may use
=IFERROR(REGEXEXTRACT(TO_TEXT(SPLIT(REGEXREPLACE(I252;"[-/() ]+"; ""); CHAR(10))); "(?:\+|00)?(?:30)?(69\d{8})"))
See the regex demo and the Google Sheets screenshot below:
The regex matches
(?:\+|00)? - an optional + or 00
(?:30)? - an optional 30
( - start of the capturing group (only this value will be returned):
69 - 69 value
\d{8} - eight digits
) - end of the group.
You might consider appending \b at the end of the regex to avoid matching the 8 digits in chunks of more than 8 digits.
Note that the separator cleaning regex is [-/() ]+ now, it matches 1 or more -, /, (, ) and spaces.
The solution to your problem is to make use of a regex lookbehind (although I do not know if Google Sheets supports this).
A regex lookbehind matches a pattern, but without including in the result. The syntax for this, with your example, is:
(?<=69)\d{10}
The picture below is taken from https://regex101.com/ (which is a super-useful tool when working with regexps).
Regex lookahead, lookbehind and atomic groups has some more examples of how lookaheads and lookbehinds work.
all you need is:
=ARRAYFORMULA(IFNA(REGEXREPLACE(REGEXEXTRACT(A1:A&""; "69.*"); "\s|/|\D+"; )))
or better:
=ARRAYFORMULA(IFNA(REGEXEXTRACT(REGEXREPLACE(A1:A&""; "\D+"; ); "69.{8}")))
I am looking for a regex expression matching all numbers between 55 up to 300 including decimals (e.g. 55.1234 or 66.324).
https://regex101.com/r/aPlUs0/3
I know how to obtain the results for 50 up to 300, but do not know how to adapt the code.
^(?:[6-9]\d|[1-2]\d{2,2})(?:\.\d+)?$|^300$
How to adapt the regex expression to match numbers between 55 to 300?
You change your regex to
^(?:5[5-9]|[6-9]\d|[1-2]\d{2})(?:\.\d+)?$|^300$
Regex Demo
On side note:- \d{2,2} is same as \d{2}
The regex you have will not match 300.00 you can extend it for this case too
^(?:5[5-9]|[6-9]\d|[1-2]\d{2})(?:\.\d+)?$|^300(?:\.0+)?$
Regex Demo
This does the job:
^(?:5[5-9]|[6-9]\d|[12]\d{2})(?:\.\d+)?$|^300$
I am novice in regex. Like to know the below date pattern.
(\\d{2}(0[1-9]|1[012]|[0]{2}))
I just know,
0[1-9] is 01 or 12 or.... 19
1[012] is 10 or 11 or 12
[0]{2} is 0000 ?
\\d{2} is ?
\d is a predefined character class that is generally equivalent to [0-9] (sometimes it also includes unicode digits, depending on the regex engine). Moreover, {n} is a quantifier, and X{n} matches X exactly n times. Therefore, \d{2} matches 2 consecutive digits.
Also, [0]{2} is 2 consecutive 0s: 00 (not 0000).
You're also slightly off about 0[1-9]: it matches any of 01, 02, ..., 09 (1 can't be at the start). You're correct about 1[012].
Overall, this is what your regex looks like:
If you want to read more about them, a great online reference regarding regular expressions is regular-expressions.info.
Note that in the above answer I've assumed you mean \d by \\d, and have used the latter because you're representing the regex in a string format that requires \s to be escaped. When representing generic regexes, however, it's best to leave \s unescaped. In other words, \\d might be interpreted as a literal backslash followed by a d, so \\d{4} would match \dddd. Presumably this isn't what you mean;