Regex picking up string that contain 2 dash - regex

I am new to regrex.
Will want to pick up a list of bank number with many others text in it.
The bank number can be e.g 111-123456-1 or 111-12345-1 or 111-1-123456
How should i write this regex.
Thanks in advance

Use this regular expression
\d+-\d+-\d+
It will match the bank numbers that you gave as examples:
111-123456-1 // Matches
111-12345-1 // Matches
111-1-123456 // Matches
If you want a better understanding of the regex, check this out:
https://regex101.com/r/ncPZoQ/1
Credits to #ALFA

Related

Regex for for Phone Numbers allowing for only 6 to 20 characters

Regex beginner here. I've been trying to tackle this rule for phone numbers to no avail and would appreciate some advice:
Minimum 6 characters
Maximum 20 characters
Must contain numbers
Can contain these symbols ()+-.
Do not match if all the numbers included are the same (ie. 111111)
I managed to build two of the following pieces but I'm unable to put them together.
Here's what I've got:
(^(\d)(?!\1+$)\d)
([0-9()-+.,]{6,20})
Many thanks in advance!
I'd go about it by first getting a list of all possible phone numbers (thanks #CAustin for the suggested improvements):
lst_phone_numbers = re.findall('[0-9+()-]{6,20}',your_text)
And then filtering out the ones that do not comply with statement 5 using whatever programming language you're most comfortable.
Try this RegEx:
(?:([\d()+-])(?!\1+$)){6,20}
Explained:
(?: creates a non-capturing group
(\d|[()+-]) creates a group to match a digit, parenthesis, +, or -
(?!\1+$) this will not return a match if it matches the value found from #2 one or more times until the end of the string
{6,20} requires 6-20 matches from the non-capturing group in #1
Try this :
((?:([0-9()+\-])(?!\2{5})){6,20})
So , this part ?!\2{5} means how many times is allowed for each one from the pattern to be repeated like this 22222 and i put 5 as example and you could change it as you want .

Regex for validation of a street number

I'm using an online tool to create contests. In order to send prizes, there's a form in there asking for user information (first name, last name, address,... etc).
There's an option to use regular expressions to validate the data entered in this form.
I'm struggling with the regular expression to put for the street number (I'm located in Belgium).
A street number can be the following:
1234
1234a
1234a12
begins with a number (max 4 digits)
can have letters as well (max 2 char)
Can have numbers after the letter(s) (max3)
I came up with the following expression:
^([0-9]{1,4})([A-Za-z]{1,2})?([0-9]{1,3})?$
But the problem is that as letters and second part of numbers are optional, it allows to enter numbers with up to 8 digits, which is not optimal.
1234 (first group)(no letters in the second group) 5678 (third group)
If one of you can tip me on how to achieve the expected result, it would be greatly appreciated !
You might use this regex:
^\d{1,4}([a-zA-Z]{1,2}\d{1,3}|[a-zA-Z]{1,2}|)$
where:
\d{1,4} - 1-4 digits
([a-zA-Z]{1,2}\d{1,3}|[a-zA-Z]{1,2}|) - optional group, which can be
[a-zA-Z]{1,2}\d{1,3} - 1-2 letters + 1-3 digits
or
[a-zA-Z]{1,2} - 1-2 letters
or
empty
\d{0,4}[a-zA-Z]{0,2}\d{0,3}
\d{0,4} The first groupe matches a number with 4 digits max
[a-zA-Z]{0,2} The second groupe matches a char with 2 digit in max
\d{0,3} The first groupe matches a number with 3 digits max
You have to keep the last two groups together, not allowing the last one to be present, if the second isn't, e.g.
^\d{1,4}(?:[a-zA-z]{1,2}\d{0,3})?$
or a little less optimized (but showing the approach a bit better)
^\d{1,4}(?:[a-zA-z]{1,2}(?:\d{1,3})?)?$
As you are using this for a validation I assumed that you don't need the capturing groups and replaced them with non-capturing ones.
You might want to change the first number check to [1-9]\d{0,3} to disallow leading zeros.
Thank you so much for your answers ! I tried Sebastian's solution :
^\d{1,4}(?:[a-zA-z]{1,2}\d{0,3})?$
And it works like a charm ! I still don't really understand what the ":" stand for, but I'll try to figure it out next time i have to fiddle with Regex !
Have a nice day,
Stan
The first digit cannot be 0.
There shouldn't be other symbols before and after the number.
So:
^[1-9]\d{0,3}(?:[a-zA-Z]{1,2}\d{0,3})?$
The ?: combination means that the () construction does not create a matching substring.
Here is the regex with tests for it.

Regex Number Below 90

I need to validate that percent complete is < 90.00, so basically 89.99 and below.
I was able to get regex to work with whole numbers:
^(?:[0-9]|(?:[1-8][0-9]))$
However, I need to be able to match one the decimal too and find it within the below string.
Endpointgroup Name::ALL::Endpointgroup Description::::SQLRun TS::2017-06-19 14:15:02::ORIGINAL_NODE=CE01::ORIGINAL_NODE=CE01::Total EP::940256::Completed EP::869655::Job Status::W::Percent Complete::92.49
This will capture strings where the number following the Complete:: is less or equal 89.99. You can get the number from the first capturing group.
Complete::([0-8]?[0-9]\.[0-9][0-9])
It is quite ugly to do with regex. See the posts
Validate max-min with regex and Use regex to compare numbers

Regex - String contains 6 digits

I'm trying to write a regex to parse a bank sort code from a database.
The reason I need a regex is that the sort code might be contained in a sentence.
But also, it might not be a sort code at all because the people entering data into the database some times put bank account numbers and phone numbers into the sort code column.
I can use
^[^0-9]*[0-9]{6}[^\d]*$
which works on
"blah123456blah"
but not on
"Emloyee 12's srt code : 123456"
Anything else I've tried gives me a match for 6 or more digits within a string (which is then most likely a bank account number).
Any help is greatly appreciated.
You say you are using
[0-9]{2}\s*-?\s*[0-9]{2}\s*-?\s*[0-9]{2}
To add the boundaries like you need, add (^|[^0-9]) (either the string start position (^) or (|) a non-digit ([^0-9])) in front and ([^0-9]|$) (matching a non-digit or the end of string position ($)) at the end:
(^|[^0-9])[0-9]{2}\s*-?\s*[0-9]{2}\s*-?\s*[0-9]{2}([^0-9]|$)
See the regex demo.

Regular Expression to validate Solo debit card

I would like a regular expression that would enable me to validate a Solo debit card.
The card number has IIN ranges of 6334 and 6767 and a length of 16, 18 , 19. Though this is not in use currently, I would like to learn how I could write a regex for it.
Help would be greatly appreciated!
Thanks!
This should do it:
(^(6334)[5-9](\d{11}$|\d{13,14}$)) |(^(6767)(\d{12}$|\d{14,15}$))
Regex for Solo debit card:
(^(5[0678])\d{11,18}$)(^(6[^05])\d{11,18}$)(^(601)[^1]\d{9,16}$)(^(6011)\d{9,11}$)(^(6011)\d{13,16}$)(^(65)\d{11,13}$)(^(65)\d{15,18}$)(^(49030)[2-9](\d{10}$\d{12,13}$))(^(49033)[5-9](\d{10}$\d{12,13}$))(^(49110)[1-2](\d{10}$\d{12,13}$))(^(49117)[4-9](\d{10}$\d{12,13}$))(^(49118)[0-2](\d{10}$\d{12,13}$))(^(4936)(\d{12}$\d{14,15}$))
Here you will find details along with others!
I saw in a comment you wanted dashes. You should update your question to reflect this.
The following will match with dashes. It matches the start of string, the first possible sequence of numbers, then a sequence of a dash then four numbers three times, then either end of string, or 2 to 3 digits and end of string.
^(6767|6334)(-\d{4}){3}($|\d{2,3}$)
Here are some results
6334-1231-1231-1231 // works
6767-1312-1231-1231123 // works
6334-1231-1231-1231 // works
6767-1312-1231-12312 // fails last sequence is 5 digits
6868-1232-1233-1231 // fails start is not valid
6767-1231-1232-2312-1 // fails additional dash
I saw another answer checked for digits 5-9 after 6334. If that is required, the new regex is
^(6334-[5-9]|6767-\d)\d{3}(-\d{4}){2}($|\d{2,3}$)
You can test with this REY