I am trying a regex for the number which should not start with 0 and can have maximum 10 digits, I tried the following regex but it is not working
1. ^([1-9]+)([0-9]+){1,10}$
2. ^(([1-9])+([0-9])+{1,10})$
3. ^([1-9]+)([0-9]*){1,10}$
but it is not working
You can try
^[1-9]{1,10}$
See a demo
Related
Regex to categorize phone numbers. Numbers with 2 of the same digit in the last 4 not adjacent to each other are easier to remember and therefore more valuable. So given 10 digit number how can I match if 2 of the last 4 digits are the same non consecutively? Ex. 2155553747, 2158558284, 7034651215. Thanks in advance for the help.
If you want to use a regular expression for that, and you are okay with the condition, that at least 2 digits of the last 4 digits are the same, you could use the following regular expression:
^\d{6}(?:(\d)\d\d\1|(\d)\d\2\d|(\d)\3\d\d|\d(\d)\d\4|\d(\d)\5\d|\d\d(\d)\6)$
Here is a live example: https://regex101.com/r/t6n1uP/1
Masochistic approach:
/^\d{6}(\d?0[^0]{1,2}0|\d?1[^1]{1,2}1|\d?2[^2]{1,2}2|\d?3[^3]{1,2}3|\d?4[^4]{1,2}4|\d?5[^5]{1,2}5|\d?6[^6]{1,2}6|\d?7[^7]{1,2}7|\d?8[^8]{1,2}8|\d?9[^9]{1,2}9)/m
A test
Far from ideal, but something to start from
I have a set of age data, like below;
1
2
3
4
5
6
7
8
9
10
1,1
1,2
1,3
2,12
11,13,15
7,8,12
12,15
14,16,17
15,6
13,11,10,2
And so on... I am trying to use Regex in to target a 'mixed' range of childrens ages. The logic requires at least a combination of 2 childen (so requires one of the lines with a comma), with at least one aged under 10 (min is 1), and at least one aged equal or greater to 10 (max 17).
My expected results from the above would be to return these lines below, and nothing else;
2,12
7,8,12
15,6
13,11,10,2
Any advice would be appreciated on how to resolve? Thanks in advance, I am continuing to try to correct.
You can use this regex to meet your requirements:
^(?=.*\b[1-9]\b)(?=.*\b1[0-7]\b)[0-9]+(?:,[0-9]+)+$
RegEx Demo
There are 2 lookaheads to assert 2 numbers one between 1-9 and another between 10-17
([1-9]) matches a number that should be between 1 and 9
1[0-7] matches a number that should be between 10 and 17
[0-9]+(?:,[0-9]+)+ in the regex is for matching 1 or more comma separated numbers in the middle.
You can do it with
\b\d,1[0-7]\b
provided the ages always are sorted (youngest to oldest).
If the age of 0 isn't allowed, change to
\b[1-9],1[0-7]\b
It checks for a single digit followed by a comma and one followed by a single digit in the range 0-7.
See it here at regex101.
This question already has answers here:
Regex: how to only allow integers greater than zero
(6 answers)
Closed 6 years ago.
I have a std::string, with a text as such
name0 0x3f700000 0x160000 1 0
or
name1 0x3f700000 0x760000 0 23
etc..
What I would like to know is if the last number in this line is greater than 0 and the number before is 1.
I did this but it doesn't work, always it returns a match.
std::regex_search(buffer, match, std::regex(std::string("(^|\n)") +
m_name + " [0-9a-fA-Fx]* [0-9a-fA-Fx]* 1 [1-9a-fA-Fx]*"));
Can you say where the error is? It seems to know when the number before is 1 but that last number seems to be going wrong.
You can use
[1-9][0-9]*$
to check if the number is greater than 0
What it does?
[1-9] Matches 1 to 9.
[0-9]* Matches zero or more digits
$ Matches end of string.
The full regex can be
name0 [0-9a-fA-Fx]* [0-9a-fA-Fx]* 1 [1-9][0-9]*$
Regex Demo
You can use this regex
1\s+[1-9]\d*$
Regex Demo
or more specifically
^name\d+\s+0x[0-9a-f]+\s+0x[0-9a-f]+\s+1\s+[1-9]\d*$
Regex Demo
I am trying to accept only 7 digit long number not starting with 0 or 1
7089097 - OK
0089097 - Not good
1089097 - Not good
This is what i tried:
^\[2-9][0-9]{7}$
And not working:)
This regex will work:
^[2-9][0-9]{6}$
Out of 7 digits 1 is consumed by first position 2-9 and then next 6 digits can be from 0-9
You can try this:
^[2-9][0-9]{6}$
Need regular expression which have:
Maximum 8 digits before decimal(.) point
Maximum 4 digits after decimal point
Decimal point is optional
Maximum valid decimal is 8 digits before decimal and 4 digits after decimal
So 99999999.9999
The regular rexpression I have tried ^\d{0,8}[.]?\d{1,4}$ is failing for 123456789
and more than this. means it is taking more than 8 digits if decimal point is not available.
Tested here : http://regexpal.com/
Many many thanks in advance!
^\d{0,8}(\.\d{1,4})?$
You can make the entire decimal optional
You can try this:
^\d{1,8}(?:\.\d{1,4})?$
or
^[1-9]\d{0,7}(?:\.\d{1,4})?$
If you don't want to have a zero as first digit.
You can allow this if you want: (.1234)
^[1-9]\d{0,7}(?:\.\d{1,4})?|\.\d{1,4}$
Any of the above did not work for me.
Only this works for me
^([0-9]{0,2}((.)[0-9]{0,2}))$
This regex is working for most cases even negative prices,
(\-?\d+\.?\d{0,2})
Tested with the following,
9
9.97
37.97
132.97
-125.55
12.2
1000.00
10000.00
100000.00
1000000.00
401395011
If there is a price of $9.97, £9.97 or €9.97 it will validate 9.97 removing the symbol.
1-(\$+.[1-9])
2-(\£+.[1-9])
You can use this expression for complete price digits.
I'm using this:
^[1-9]\d{0,7}(\.\d{1-4})$
^ = the start of the string
[1-9] = at least the string has to begin with 1 number between 1 and 9
\d{0,7} = optional or max 7 times d (digit: a number between 0 and 9)
() = create a group like a substring
. = need a .
\d{1-4} = digit repited max 4 time
$ end of the string
For price validation we can not allow inputs with leading repeating zeros like 0012 etc.
My solution check for any cases. Also it allows maximum 2 decimal point after the dot.
^(?:0\.[0-9]{1,2}|[1-9]{1}[0-9]*(\.[0-9]{1,2})?|0)$