This question already has an answer here:
Reference - What does this regex mean?
(1 answer)
Closed 3 years ago.
I need to have a regular expression to restrict the number of digits in a string which may contain alphabets or any other characters along with digits. Is this possible with regular expressions ?
The idea is to anchor beginning and end of string and allow exactly n repetitions of a digit with something else. For example, exactly 6 digits in a string:
^\D*(\d\D*){6}$
Related
This question already has an answer here:
Regular expression for a string that does not start with a sequence
(1 answer)
Closed 1 year ago.
I need to generate a regular expression to validate that the string does not start with 5 digits.
NOT VALID: 12345testing123asd
VALID: 1234testing1234
testing12345
testing
I tried to get the first five chars ^.{0,5} but I do not know hot to add the restriction of \D to those first 5 chars
Also, I tried with this [^0-9][^0-9][^0-9][^0-9][^0-9] but I do not know how to do to include the strings that starts with 4 or less numbers
Could you please help me with this? I am a rookie :(
If your RegExp flavor of choice supports negative lookaheads, this pattern will match if the string is valid (does not start with 5 or more consecutive digits):
^(?!\d{5,})
Regex101
Matches:
1234testing1234
testing12345
testing
Does not match:
12345testing123asd
This question already has an answer here:
Reference - What does this regex mean?
(1 answer)
Closed 2 years ago.
I have a string in the following format:
ABC12233434343DEF
How can I extract only:
ABC12233434343
I want to leave out the ending set of characters of whatever length they might be.
There are several ways this is one:
.*?\d+
It will match anything at the beginning that is followed by numbers.
It may be also posible to limit the characters it can match initially, like if you was capital letters from A-Z, for example:
[A-Z]+\d+
Online Demo
This question already has answers here:
Match exact string
(3 answers)
Closed 4 years ago.
Hi this is my example 0xc1e5017fbc68aa3e56aa580708de9aa123d62d18
This is my reg ex ^0x[a-fA-F0-9]{1,40}. What I'm doing is 0x which is compulsory after that we can enter upto 40 alpha numeric digits. But not special characters. What should I do here so it will match correctly?
Your issue is that you need to assert where the string ends, or else you will match up until a special character is found, and get undesired matches.
So with your current regex and test string 0xc1!, 0xc1 would be matched, even though it is an invalid match.
How about using: ^0x[a-fA-F0-9]{1,40}$
This question already has answers here:
PHP: RegEx for string with 3-9 letters and 5-50 numbers
(2 answers)
Closed 5 years ago.
I want to match a string that has the following requirements:
The string contains 5 to 10 digits. [0-9]
Contains 2 to 3 letters. [a-z]
for example
123a2bc12
s123d456
This is my regular expression. /^\d*[a-z]\d*[a-z]\d*[a-z]?\d*$/. But this can only limit the number of letters.
It isn't pretty but this should be what you're looking for:
^(?=(?:[^a-zA-Z]*[a-zA-Z]){2,3}[0-9]*$)(?=(?:[^0-9]*[0-9]){5,10}[A-Za-z]*$).*$
I think you want to this
s=re.search(r'(\w+)','123a2bc12').group(1)
print s #The output is '123a2bc12'
This question already has answers here:
Using regular expressions to validate a numeric range
(11 answers)
Closed 6 years ago.
I have to write a regular expression pattern in java for numbers in the range -100.00 to 9999.99 . The allowable number of decimal places is exactly 2. Please help me.
If I understood your question correctly, you are asking for the range from -100.00 to +9999.99. Hence the correct answer would be:
(?<!\d)(-\d\d?|-100|(?<!-)\d{1,4})\.\d{2}(?!\d)
Checking on both sides to validate that you aren't getting part of a number.
-\d{3,4}\.\d{2}
Explanation:
- - match the minus
\d{3,4} - match three or four digits
\. - match fullstop
\d{2} - match two digits