I'm trying to create a regex to
valid following type string only
first 2 characters 0 to 9
next 3 characters 000 to 366 then 501 to 866
next 4 characters 0 to 9
finally x or X
so I did that using following
([0-9]{2}(001|002|003|004|005|006|007... |366|501|...|866)[0-9]{4}[x|X]$)
so this can validate properly 900033618x
but this also taking 9001033618x as valid onces
how to restrict to 9 character length before x or X
I tried do this, like following
(^\d[[0-9]{2}(001|002|003|004|005|006|007... |366|501|...|866)[0-9]{4}]{9}[x|X]$)
but this not working
Just do what you say:
^[0-9]{2}(?:[01][0-9][0-9]|[24]00|3(?:6[6-9]|[7-9][0-9]))[0-9]{4}[xX]$
Note: watch beginning caret ^
Related
I have this multi-line text, I want to extract the numerical value before the 'Next' text (in this case 13). The numerical values will change, but the location will stay the same, it indicates total # of pages on website. I am having trouble writing the correct regex to return this value:
Previous
1
2
3
...
13
Next
Showing 1 - 100 of 1227 Results[EXTRACT]
pattern =re.compile(r'(\d{1,2})\r\nNext', re.M)
result = pattern.match(text)
The expected return value is 13.
import re
t = """Previous
1
2
3
...
13
Next
Showing 1 - 100 of 1227 Results[EXTRACT]"""
re.search(r"\d+(?=\s+Next)", t).group(0)
Returns: '13'
The regular expression does a lookahead assertion to see if there is any amount (>1) of digits followed by any amount (>1) of whitespace characters followed by the word Next.
I am trying to create a RegExp in oracle to match a string with the following criteria,
Length 11 characters.
The 2,5,8,9 characters are letters [A-Z ] except ( S,L, O,I,B and Z).
The 1,4,7,10,11 characters are numeric [0-9].
3rd and 6th will b either a number or a letter.
You'll want to use the following regex with REGEXP_LIKE(), REGEXP_SUBSTR(), etc:
^[0-9][AC-HJKMNP-RT-Y][A-Z0-9][0-9][AC-HJKMNP-RT-Y][A-Z0-9][0-9][AC-HJKMNP-RT-Y]{2}[0-9]{2}$
Hope this helps.
Make a fancy Character List
I just make a fancy character list excluding the alphabetical upper case letter you cited. This is similar to David Faber's answer.
Here is my fancy character list:
-'[AC-HJKMNPQRT-Y]' -Oracle's documentation states that the hyphen is special in that it forms a range when in this character list.
To make this pattern succinct, I noticed that for the most part, this string follows a pattern of digit, alphabet, alphabet pattern. Consequently, I placed this in a subexpression grouping which occurs 2 times (quantifier follows).
SCOTT#db>WITH smple AS (
2 SELECT
3 '123456789ab' tst
4 FROM
5 dual
6 UNION ALL
7 SELECT
8 '1CC4DD7EE01'
9 FROM
10 dual
11 UNION ALL
12 SELECT
13 '1CB4DD7EE01'
14 FROM
15 dual
16 UNION ALL
17 SELECT
18 '1C44D67EE01'
19 FROM
20 dual
21 ) SELECT
22 smple.tst,
23 regexp_substr(smple.tst,'^(\d[AC-HJKMNPQRT-Y](\d|[AC-HJKMNPQRT-Y])){2}\d[AC-HJKMNPQRT-Y]{2}\d{2}$') matching
24 FROM
25 smple;
TST MATCHING
-------------------------
123456789ab
1CC4DD7EE01 1CC4DD7EE01
1CB4DD7EE01
1C44D67EE01 1C44D67EE01
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.
In my MVC application I define validation using the following RegEx
[RegularExpression(#"\d{8}0[1-2]\d{3}", ErrorMessage = "Must be numeric, 12 or 13 characters long & Format xxxxxxxx[01 or 02]xxx")]
But I want to allow 12 or 13 characters. The d{3} appears to be forcing that overall I have 13 characters input
To allow it to accept 12 or 13, I have changed d{3} to d{2} and its accepting 12 now.
But - can I be sure it will still take 13 characters?
Must be numeric, 12 or 13 characters long & Format xxxxxxxx[01 or 02]xxx
To allow digits 1 or 2 after first nine digits,
^\d{8}0[12]\d{2,3}$
^^^^ : Allow 1 or 2 after `0`
^^^^^^^ : Any two or three digits
Note that [12] can also be written as (1|2) using OR/alteration.
Demo
http://regexr.com?32uvo
What I currently have:
\b(?=[A-Z\d]{10})(?:[A-Z]*\d){0,2}[A-Z]*\b
This would only match a string with a length of 10. I would like to change it to between 9 and 10 characters, where 2 can be numbers. Why doesn't this work?
\b(?=[A-Z\d]{9,10})(?:[A-Z]*\d){0,2}[A-Z]*\b
AFAIK, {9,10} should be the length interval.
You were close
\b(?=[A-Z\d]{9,10}\b)(?:[A-Z]*\d){0,2}[A-Z]*\b
--
|->you missed this
try it here
So this regex would match a word that contains 9 to 10 characters[upper case and digits] that contain 1 to 2 digits
if you want to match the whole string you better use ^(start of the string) and $(end of the string)