Hi I need a regular expression for phone number looking like +NNNNN, where + is optional and NNNN are arabic numbers only (from 0 to 9).
The phone number must be between 3 and 20 symbols. I use the following expression [+]{0,1}[0-9]{3,20}$ but it is not working correctly.
Where am I making a mistake?
You didn't anchor the start of your pattern with ^ but you did it on the end with $
This should work:
^\+?[0-9]{3,20}$
Just add anchor at the begining of the regex:
^[+]?[0-9]{3,20}$
^[+]{0,1}[0-9]{3,20}$
should work, you have to use ^ to match from the beginning
Related
Hello I need to exclude sequence of digits from 890000 till 890001;
890002 to 899999 is acceptable
Is it possible doing using regular expression?
No need for regex.
If Value >= 890002 And Value <= 899999 Then
' Accept
End If
Ok, if you insist on using regex (may be for learning purpose):
In this simple case it is actually easier to exclude those two number and match the rest:
^89(?!000[12])\d{4}$
Explanation:
^ match from start of text
89match 89
(?!000[12]) negative look ahead for 3 times zero and one of characters in the character group (1 or 2). If this doesn't block the match:
\d{4} match 4 digits
$ match end of text.
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
Is there a regular expression for? :
String of length 8
First two chracters fixed 'UE' or 'ue'
remaining 6 characters must be digits [0-9]
Eg: https://regex101.com/r/PufypE/1
The expression i tried
\^(UE|ue){2}[0-9]{6}\
but its not working (no match found!)
You want:
\b(UE|ue)[0-9]{6}\b
You don't need the {2} next to the (UE|ue) since you are specifying those exactly. The \b is a word boundary so this will match a list like you put in the comment: UE123456,ue654321 This is a good site to play with a regex on for this kind of stuff: http://regex101.com
Regex should be:
^[Uu][Ee][0-9]{6}$
(UE|ue){2} in your regex would match 2 occurrences of UE or ue
There are two scenarios as below:
1234/12345
12345/1234
Client using a regex: ^\d{4}\/\d{4}$
The above regex will not work due to the start and end characters being introduced.
Can someone suggest any modifications to ^\d{4}\/\d{4}$ regex which can extract the above values using start and end pattern i.e. ^ and $ ?
Leverage Regex range ({,}):
^\d{4,5}\/\d{4,5}$
\d{4,5} matches 4 to 5 digits (\d)
Using this for an example string
+$43073$7
and need the 5 number sequence from it I'm using the Regex expression
#"\$+(?<lot>\d{5})"
which is matching up any +$ in the string. I tried
#"^\$+(?<lot>\d{5})"
as the +$ are always at the beginning of the string. What will work?
If you use anchor ^, you need to include the + symbol at the first and don't forget to escape it because + is a special meta character in regex which repeats the previous token one or more times.
#"^\+\$(?<lot>\d{5})"
And without the anchor, it would be like
#"\$(?<lot>\d{5})"
And get the 5 digit number you want from group index 1.
DEMO
I would match what you want:
\d+
or if you only want digits after "special" characters at the start of input:
^\W+(\d+)
grabbing group 1