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$
Related
I need a regular expression to be used in the form.
The rule is simple, the format must be MMAYY.
Example of valid MMAYY:
01A21
12B20
01A22
Example of invalid MMAYY:
01121
22A21
I tried the below but it will check for MMYY only.
^0[1-9]|^(11)|^(12)[0-9][0-9]$
Any help will be appreciated. Thank you!
Your regex is using alternation with incorrect grouping. Moreover you are not matching mont number 10 and you are also not matching a letter in the middle.
You may use this regex:
^(?:0[1-9]|1[0-2])[A-Z][0-9]{2}$
RegEx Demo
RegEx Demo
^: Start
(?:0[1-9]|1[0-2]): Match a 2 digit number for month number, of the form 01, 02, 03, ... 10, 11, 12
[A-Z]: Match an uppercase letter
[0-9]{2}: Match 2 digits
$: End
I think your regex misses the letter.
This should do what you want:
(^0[1-9]|^(10)|^(11)|^(12))[A-Z]([0-9][0-9])$
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}")))
How can I get an regex expression that allows:
0.00 to 50.00 and also comma as decimal separator so
0,00 to 50,00
I have gotten as far as ([0-5]{1})?([0-9]{1})([,][0-9]{1,2})?
but there are still situations in which it fails. I have searched on line but could not find the right answer.
ADDED:
A small change in requirements. Actually it should be from 0.01 to 50.00, and 0,01 to 50,00. (But with the answers below I think I managed to adapt the regex strings so this is also matched)
There is a regex for range generator here. Generated and played with it, came up with this
^(?:[1-4]?\d[.,]\d\d?|50[.,]00?)$
Added non capturing group, little modifications and ^ start / $ end anchor. See demo at regex101.
For optional decimal part, how about this: ^(?:[1-4]?\d(?:[.,]\d\d?)?|50(?:[.,]00?)?)$
This regex should cover almost all cases matching numbers from 0.00 to 50.00,
^(?=.)(?:(?:(?:0|[1-4]?\d)?(?:[,.]\d{1,2})?)|50(?:[.,]00?)?)$
Explanation:
^ - Start of string
(?=.) - Positive look ahead to avoid matching empty string
(?: - Start of first non-grouping pattern
(?: - Start of second non-grouping pattern
(?:0|[1-4]?\d)? - This matches whole number from 0 to 49 and this whole number could be absent
(?:[,.]\d{1,2})? - Matches a comma or dot followed by one or two digits and this decimal part can be absent
) - Closing of second non-grouping pattern
| - Alternation for number 50 case
50(?:[.,]00?)?) - Matches 50 followed by either comma or dot followed by 0 or 00 where decimal part is optional
) - Closing of first non-grouping pattern
$ - End of string
Regex Demo
Edit:
For discarding zero value numbers, you can just add a negative lookahead (?!0*[.,]?0*$) in current regex and use this regex,
^(?=.)(?!0*[.,]?0*$)(?:(?:(?:0|[1-4]?\d)?(?:[,.]\d{1,2})?)|50(?:[.,]00?)?)$
Regex Demo rejecting zero valued numbers
does this one work for you?
(50([.,]0{1,2})?)|([0-4]?[0-9]([.,][0-9]{1,2})?)
I just need to find phone number in description and remove it using regular expressions. Phone numbers would be in following formats:
998991234567
+998 99 123 45 67
1234567
991234567
(998)901234567
I have found following regex, but do not know what to change:
/^(+\d{1,3}[- ]?)?\d{12}$/
Based on your example of numbers format, this regex will work
/([0-9]{12})|(\([0-9]{3}\)[0-9]{9})|(\+[0-9]{3} [0-9]{2} [0-9]{3} [0-9]{2} [0-9]{2})|[^0-9]([0-9]{7})[^0-9]|[^0-9]([0-9]{9})[^0-9]/gm
You can use the pip | character to set more than one regex format to match.
Also you can test your regex in https://regex101.com/r/fzB1nL/1
I have files with these filename:
ZATR0008_2018.pdf
ZATR0018_2018.pdf
ZATR0218_2018.pdf
Where the 4 digits after ZATR is the issue number of magazine.
With this regex:
([1-9][0-9]*)(?=_\d)
I can extract 8, 18 or 218 but I would like to keep minimum 2 digits and max 3 digits so the result should be 08, 18 and 218.
How is possible to do that?
You may use
0*(\d{2,3})_\d
and grab Group 1 value. See the regex demo.
Details
0* - zero or more 0 chars
(\d{2,3}) - Group 1: two or three digits
_\d - a _ followed with a digit.
Here is a PCRE variation that grabs the value you need into a whole match:
0*\K\d{2,3}(?=_\d)
See another regex demo
Here, \K makes the regex engine omit the text matched so far (zeros) and then matches 2 to 3 digits that are followed with _ and a digit.
(?:[1-9][0-9]?)?[0-9]{2}(?=_[0-9])
or perhaps:
(?:[1-9][0-9]+|[0-9]{2})(?=_[0-9])
(https://www.freeformatter.com/regex-tester.html, which claims to use the XRegExp library, that you mention in another answer doesn't seem to backtrack into the (?:)? in my first suggestion where necessary, which makes it very different from any regex engine I've encoutered before and makes it prefer to match just the 18 of 218 even though it starts later in the string. But it does work with my second suggestion.
([1-9]\d{2,3})(?=_\d)
{x,y} will match from x to y times the previous pattern, in this case \d
Edit: from your own regex it looked as you wanted the part of the number which starts with a non-zero. However since your examples include leading 0s, maybe you really wanted :
(\d{2,3})(?=_\d)
Which will give you the last 3 digits before underscore unless there are only 2 digits.
I propose you:
^ZATR0*(\d{2,3})_\d+\.pdf$
demo code here. Result:
Match 1 Full match 0-17 ZATR0008_2018.pdf Group 1. 6-8 08
Match 2 Full match 18-35 ZATR0018_2018.pdf Group 1. 24-26 18
Match 3 Full match 36-53 ZATR0218_2018.pdf Group 1. 41-44 218