Regex Number Capture Without Percent Sign [duplicate] - regex

This question already has answers here:
What special characters must be escaped in regular expressions?
(13 answers)
How do I include negative decimal numbers in this regular expression?
(17 answers)
Closed 2 years ago.
Overall Goal: I would like to be able to capture a positive or negative number that looks something like this: xxx.xxx
I am also using Google Sheets, so I cannot use any lookarounds
Example Criteria:
+123.123 ---> 123.123
+30% ---> 30
+4% ---> 4
-1% ---> -1
0 ---> 0
+12 ---> 12
-3 ---> -3
What I've Tried:
The main regex I've been using is: -?\d+.?\d*. The problem with this one is that it also captures the percent signs, which I do not want. Percent signs seem to be considered part of the number.
I've also tried: -?\d+.?\d+. This one runs to the problem of not capturing single digit numbers.

. matches any character (Google uses RE2). You should escape it.
-?\d+\.?\d*

Related

Multi-part Regular Expression [duplicate]

This question already has answers here:
Comma Separated Numbers Regex
(6 answers)
Closed 3 years ago.
I have the requirement to restrict a non-required textbox to only numbers (0-9) with a separator of ';'. The pattern is that the groups can be 4 or 5 in length and can repeat n times. Anything less than 4 in a group is invalid. After 4 or 5 I need to check for the existence of a separator character ';'. This pattern can repeat n times. I have tried variations of but this doesn't seem to be working. Something simple to start out like
[0-9]{4,5};+
is invalid as I don't need the separator for only 1 number grouping.
Next I tried
^[0-9]{4,5}|[0-9]{4,4};|[0-9]{5,5};$
but this doesn't work because the existence of four digits like 1111 or five digits 11111 before gives one match before it goes awry example "11111;j" Is there a way in a regex to validate
1111
11111
1111;1111
11111;1111
11111;11111
but catch
111
111;
1111;1
11111;1
abc
in a repeating fashion?
This validate your examples.
^[0-9]{4,5}(;[0-9]{4,5})?$
Try it
It's not clare what you mean by "in a repeating fashion". If you want validate also this
1111;11111;11111;1111;11111
You can use this regex
^[0-9]{4,5}(;[0-9]{4,5})*$
Try it

RegEx for matching a number greater than 9? [duplicate]

This question already has answers here:
Using regular expressions to validate a numeric range
(11 answers)
Closed 3 years ago.
How to put a number greater than 9 to regexp character set?
For example, I can do ^[01236]$, but what if I want to put 100 as an option to the set?
How do I solve this problem?
'\d+' can find number having 1 or more digits
If a number is greater than 9, it is more than 2 digits and the first digit is not 0. So the regex you might want to use is: ^[1-9][0-9]+$
If you want to put a specific multi character strings you can use:
^(10|100|200|301|601)$
Which will match 10, 100, 200, 301, and 601
test: https://regex101.com/r/bptbsx/1

Phone number regex should strictly allow 10 characters if starting with 02/03/04/07/08 [duplicate]

This question already has answers here:
Regex for Australian phone number validation
(5 answers)
Closed 4 years ago.
The below expression is being used to accept Australian phone numbers.
I need to change the expression as to strictly accept total 10 digits (without spaces) if the number starts with 02/03/04/07/08.
^\({0,1}((0|\+61)\s?(2|4|3|7|8)){0,1}\){0,1}(\ |-){0,1}[0-9]{2}(\ |-){0,1}[0-9]{2}(\ |-){0,1}[0-9]{1}(\ |-){0,1}[0-9]{3}$
It does accept 10 digits if the number is entered like 03 11 11 1 111, but without spaces 8 digit number is accepted too.
You can use the use the following regex with alternation:
^ *(?:0 *[23478](?: *\d){8}|[1-9](?: *\d)*|0 *[01569](?: *\d)*) *$
Demo: https://regex101.com/r/bet7m1/1

How to write regular expression which accept numbers between 1 to 25000 [duplicate]

This question already has answers here:
Using regular expressions to validate a numeric range
(11 answers)
Closed 4 years ago.
How to write regular expression which accept numbers between 1 to 25000>
I tried like this ^([1-2]?[1-4]?[0-9]{0,3}|25000)$
Here's a regex that will only accept a string with a number between 1 and 25000.
Without proceeding zero's.
^([1-9]\d{0,3}|1\d{4}|2[0-4]\d{3}|25000)$
It basically separates it in 4 ranges
[1-9]\d{0,3} : 1 to 9999
1\d{4} : 10000 to 19999
2[0-4]\d{3} : 20000 to 24999
25000 : 25000
A regex101 test can be found here
To find those numbers as a part of a string, you could replace the start ^ and end $ by a wordboundary \b.
Btw, in most programming languages it's often simpler to just check if it's a number that's in the accepted range. Even in HTML there's an input type for numbers where you can set the minimum and maximum.
Try
^(?!0$)((1\d|2[0-4]|\d)?\d{1,3}|25000)$
First negative lookahead will reject a value of only 0.
The group (1\d|2[1-4]|\d)? means that a 5-digit number with an initial digit of 2 requires it to be followed by a 0-4.
https://regex101.com/r/1DgbBM/4

regex - decimalised number [duplicate]

This question already has answers here:
Decimal number regular expression, where digit after decimal is optional
(17 answers)
Closed 8 years ago.
I'm very new to regex. How do I match a decimalised number. I have found ones that include $ but just need to match any number which could include decimals.
e.g.
100
100.50
707.40
150.00
It's not very advanced, but:
/\d.*?\.\d.*/
Will match:
2.0
12.00
Won't match:
2
22
Doesn't check if it's a number though.