hello i am trying to find a match in the followig format in a text file using regex and save the number into a variable.
id='12341234321234131313'
now my problem i want to consider the string a match only if the integer has a number digits between 16 and 22, is it possible to do this directly using regex or do i have to check for the length?
i would use the following if to match when the number of digits is 20
Dim rex = New Regex("id='(\d{20})'")
but what about between 2 numbers?
To check for a range of repeat lengths, use {min,max}:
"cid='(\d{16,22})'"
Related
If i have a series of strings in Python 3.x im iterating over, how do i check if they all have the right formatting of 1 letter and 12 numbers following it. I want a booleon output so i can use it in an if statment? Thanks
/[a-zA-Z]\d{12}/.test(string)
[a-zA-Z] matches any single letter capital or small
\d{12} matches 12 digits
and test() function returns true if a match is found
Regular expression in java for a string which can contain 2 digits & 10 alphabets irrespective of their position in String
Examples of string are:
1abcdefghij2
12abcdefghij
abcdefghij12
abcdefg1hij2
ab12cdefghij
Is it possible?
I think the regex you are looking for is like this.
Regex: ^(?=\D*\d\D*\d\D*$)[a-zA-Z0-9]{12}$
Explanation:
(?=\D*\d\D*\d\D*$) checks for presence of 2 digits.
[a-zA-Z0-9]{12} makes sure that the total length is 12.
Since presence of 2 digits is already checked obviously there will be 10 alphabets.
Regex101 Demo
Edit #1: Edited regex on Sebastian Proske's advice from
^(?=.*\d.*\d)[a-z0-9]{12}$ to ^(?=\D*\d\D*\d\D*$)[a-zA-Z0-9]{12}$
Yes, it's possible.
[12a-j]+ for strings not limited by length and [12a-j]{12} for string exactly 12 characters long.
You can test it here.
I have the requirement to validate a String containing two numbers separated by a dash(-) or a comma(,). Valid values are :
23.98-34.76 or 23.98,34.76
23-34 or 23,34
5-6 or 5,6
I have the following regex which is a slight modification of the answer that I received here in SO. It is covering the 1st and 2nd case above but not the third case involving single digits only.
The modified regex String that I am using is :
(\d+\.?\d+?)([-,])(\d+\.?\d+?)
Where did my regex go wrong?
Correct regex should be like this:
(\d+(\.\d+)?)[-,](\d+(\.\d+)?)
i.e. if there is a period then it is always followed by 1 or more digits.
Otherwise in your regex it will also match strings like 123.,789.
I have this
"^(?!(11111|22222|33333|44444|55555|66666|77777|88888|99999|00000))([0-9]\d{8})"
regular expression in c# code and javascript works fine but in text tag of adobe echosign doesnt works anyone have anotherway to work on texttag of echosign?
By your last comment, you need a regex to validate a string of maximum length 9 containing digits only:
^[0-9]{1,9}$
This will validate any string containing digits, with length at least 1 and not greater than 9.
If you want to avoid strings such as 098 (leading zeroes), use this instead:
^[1-9][0-9]{0,8}$
EDIT: If I understand your question well now, you can use this regex:
^(?!([0-9])\1\1-\1\1)[0-9]{3}-[0-9]{2}-[0-9]{4}$
That is assuming that echosign can handle callbacks, if not, you can use this instead:
^(?!(?:111-11|222-22|333-33|444-44|555-55|666-66|777-77|888-88|999-99|000-00))[0-9]{3}-[0-9]{2}-[0-9]{4}$
I am trying to match a group of numbers in regex that consist of one of the following:
1,2,3,4,5,6,7,8,9,10,11
But I am having trouble figuring out the regex.
For single digits this pattern worked fine "0|1|2|3|4|5|6|7|8|9" but it fails on double digit numbers. For example 12 passes as ok due to the regex finding the 1 in 12.
You can use begin and end anchors to force the whole string to be matched:
^(0|1|2|3|4|5|6|7|8|9|10|11)$
Which can be shortened to:
^(\d|10|11)$
This will work if you want to check if just one number is between 0 and 11.
^[0-9]$|^1?[0-1]$
If you want to match a string like:
1,2,3,12,32,5,1,6,8, 11
and match 0-11 then you can use the following:
(?<=,|^)([0-9]|1?[0-1])(?=,|$)
use this regex ^(0|1|2|3|4|5|6|7|8|9|(10)|(11))$