I need to combine two input patterns into one.
First symbol contains 1: ^[1]\d*$
Min, max length contains 8: .{8}
What expression should I use?
Just repeat {7} digits instead of repeating the digits with *, to ensure the string has 8 digits total:
^1\d{7}$
Related
i'm trying to make a regex to add to a input pattern (HTML) to check if is valid,
it need to be valid only if the input contain a string composed by decimal(with 1 or 2 number after comma) or integer number separated by a +
and maximum of 5 number
and it can not start or end with a + or it can not be possible to have a number with comma without number after (i use comma instead of dot for decimal)
for example
10+5,1+6,20 OK
10 OK
6+4+8,9+3+9+3 NO
10,2+4+6+ NO
10,+5 NO
i've tried with something like this but id doesn't work very well
((\d{1,3}|(\d*,\d{1,2})*)+(\+)?){1,5}
also i've tried with this:
^((\s*)|([0-9]\d{0,9}(\,\d{1,2})?%?))*(\+((\s*)|([0-9]\d{0,9}(\,\d{1,2})?%?))+){0,4}$
but it doesn't work very well with the 2 digit max for the decimal and ending +
any suggestions ??
i've made some test here:
https://regexr.com/5jsfv
it should pass the first 3 and faile on the last 4
thanks
You can use
^\d+(?:,\d{1,2})?(?:\+\d+(?:,\d{1,2})?){0,4}$
In the HTML pattern attribute use it as
pattern="\d+(?:,\d{1,2})?(?:\+\d+(?:,\d{1,2})?){0,4}"
See the regex demo.
NOTE: If you want to limit the number of digits in the integer part to be max 3, replace the \d+ with \d{1,3}:
^\d{1,3}(?:,\d{1,2})?(?:\+\d{1,3}(?:,\d{1,2})?){0,4}$
Details:
^ - start of string (implicit in pattern regex)
\d+(?:,\d{1,2})? - one or more digits and then an optional sequence of a , and one or two digits
(?:\+\d+(?:,\d{1,2})?){0,4} - zero to four occurrences of a + char followed with one or more digits and then an optional sequence of a , and one or two digits
$ - end of string (implicit in pattern regex)
I am trying to write one single formula to identify all the patterns in a column/field. For example: Below are the five different patterns
AG 5643 895468 UWEB
7546 695321 IJJK
PE 45612384
8642567921
16724385
Formula for
First pattern: Contains 4 numbers 6 numbers
'*[0-9][0-9][0-9][0-9] [0-9][0-9][0-9][0-9][0-9][0-9] *' This is not working. Can we specify the length? Something like this [0-9]{4} - 4 digit number?
First pattern should pick second one also.
3rd one: first 2 characters are alphabets 8 or 10 digit numbers
4th one: 10 digit number
5th one 8 digit number
Thanks in advance!
If you're working in MySQL you can use regular expressions with the RLIKE filter operator.
For example, WHERE text RLIKE '[0-9]{8}' finds all the rows with any consecutive sequence of eight digits in them anywhere. (http://sqlfiddle.com/#!9/44996/1/0)
WHERE text RLIKE '^[0-9]{8}%' finds the rows consisting of nothing but an eight-digit sequence. (http://sqlfiddle.com/#!9/44996/2/0)
WHERE text RLIKE '^[0-9A-Z]{2} ' finds the rows starting with two letters or digits and then a space. (http://sqlfiddle.com/#!9/44996/3/0)
You get the idea. Regular expressions have a lot of power to them, generally beyond the scope of a SO answer to explain. Beware, though. This is a common saying: If you solve a problem with e regular expression, now you have two problems. You need to be careful with them.
I need a regular expression that matches the following to be used on a web page:
-The first number must be a digit
-The length must be a minimum of 10 digits
-No spaces, alpha, special characters allowed
As my understanding, you need to check if it is a number (containing only the digits 0-9) and this number should be minimum of 10 digits.
Then the following code should work:
/^\d{10,}$/
I have a float column and I'm trying to save the value 1000000. It automatically turns it to 1e+06. How can I fix it?
To have the value returned formatted as 1000000, you can simply add integer zero to the column in the SELECT list.
SELECT mycol+0 AS mycol FROM mytable
MySQL is storing the value IEEE floating point format. (One bit for sign, a certain number of bits for the exponent, and a certain number of bits for the mantissa. This isn't really a MySQL thing, it's the standard representation for floating point values.)
As far as what's being returned, that's an issue with converting that value into string representation.
A floating point number has a large range of values. To represent the maximum value of a float (3.402823e+38) as a decimal value, that would require 38 decimal digits. The seven left most digits of the value are significant, but we'd need to add another 32 zeros/digits to indicate the position of the decimal point.
So, returning a string representation of scientific notation is a reasonable approach to returning a representation of the value.
Those two things are equivalent:
1e+06
= 1 * 10^6
= 1 * 1,000,000
= 1,000,000
It's called scientific notation (see here). mySQL uses it to display huge/tiny values, especially approximate values (see here).
You can use DOUBLE(8, 3) where 8 is the total no. of digits excluding the decimal point, and 3 is the no. of digits to follow the decimal.
My regular expression should match the strings of following formats.
a:123456, sdfsdf:765756, dskjsdkfjh: 200000 etc.
[a-zA-Z]{1,20}:\d{6}
You can try this.