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
Related
I am trying to extract the phone number and full name from a data string, but I can't figure out a regex pattern needed for extracting the said data. Can anyone help me with it?
This is the data string:
Sat, September 3rd, 10:13am - Case Lead ID: #C69-660-301C
John Doe | user#xyz.com | 5551234567
FYI, I found a regex pattern to extract email and it worked.
([a-zA-Z0-9._-]+#[a-zA-Z0-9._-]+\.[a-zA-Z0-9_-]+)
BTW, the tool I use to extract this data only supports positive lookahead regex patterns.
If your data is always structured like this on a single line with 2 pipes, you can use a negated character class with 3 capture groups.
Assuming there are no pipes in the data, and the delimiter is fixed like |
^([^|\n]+) \| ([^|\n]+) \| ([^|\n]+)$
Regex demo
Or a bit more specific matching an email like pattern and 10 digits in the last part:
^([^|\n]+) \| ([^\s#]+#[^\s#]+) \| (\d+)$
Regex demo
For a phone number:
\d{10} # will match 10 digits
\d{3}-\d{3}-\d{4} # will match a ten digit phone number with dashes
For a full name, assuming the first letters of the first and last name are capitalized and that there is a single space between the names, which is not always the case:
[A-Z][a-z]+\ [A-Z][a-z]+
If there are other number formats that you may need, or names that have punctuation, accent marks, or initials, I can amend my answer.
In case it is helpful, this is the website that I use for practicing Regex: https://regexr.com/
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 have searched around and cannot find an answer to my problem.
I have a range of numbers that I need to match against, it can be any one of these numbers but it must be a full match on a number not partially matched, see below:
Numbers to match against:
4 46 64
Now if I have the number 48, the regular expression should fail as the number 48 does not exist. My regex seems to matching on all of the number 4's for example and that is my issue.
Regular Expression:
/4|46|64/g
The text to match against is:
48
Result:
0-1: 4
See my example on an online regex tester:
https://regex101.com/r/QPUsqa/1
Thanks in advance.
Just add the anchors ^ and $ to modify it to:
^(?:4|46|64)$
Click for Demo
Explanation:
^ - asserts the start of the string
(?:4|46|64) - matches either 4 or 46 or 64
$ - asserts the end of the string
I am having trouble using regex in fitnesse. I want to get a regex for a sequence of 10 digits. I tried the following-
=~/\d{10}/
and
=~/[0-9]{10}/
But these are not working. For a sample input say "1234", the above regex is passing as green.
What would be the regex to test a sequence of 10 digits in fitnesse?
Try adding start/end anchors, e.g.
=~/^\d{10}$/
or perhaps word anchors if the 10 digit number is embedded in other text:
=~/\b\d{10}\b/
your regex match sequence of only 10 digits, but not 4
you must write \d{1,10}