Regular expression to match exact 11 digits numbers [duplicate] - regex

This question already has answers here:
regular expression to match exactly 5 digits
(5 answers)
RegEx match exactly 4 digits
(4 answers)
Closed 2 years ago.
I need a regular expression to match exact 11 digits(no spaces, no alphabets). Valid values are
12345678987 - Valid
123456789876 - not valid because it has more than 11 digits
1234 5678987 - Not valid (since it has space)
11223344556 - valid
A1234B5678987 - not valid (because it has alphabets)
I tried the below expression but no luck
var aa = new RegExp("^[0-9]{11});
var bb = new RegExp("/d{11});( this will give valid to even 1,2,3,4)

Use start and end of string
^\d{11}$
const str = `12345678987
123456789876
1234 5678987
11223344556
A1234B5678987`;
console.log(str.match(/^\d{11}$/gm))
or using a Word Boundary:
\b\d{11}\b

Related

Numerical string withing another string [duplicate]

This question already has an answer here:
Reference - What does this regex mean?
(1 answer)
Closed 2 years ago.
What will be the regular expression to find a numerical string starting with a number other than 0 and having a length of 13 or more. This numerical string would be a substring inside a bigger alphanumeric string.
/[1-9][0-9]{12,}/
You're looking for a number from 1 to 9, then for 12 or more numbers from 0 to 9.

how to extract data with regex in python? [duplicate]

This question already has answers here:
What special characters must be escaped in regular expressions?
(13 answers)
Regex to match a word with + (plus) signs
(5 answers)
Closed 3 years ago.
My data has this struture:
ID 12354 linea+b 3
ID 15687 linea+b 7
ID 26894 linea+b 10
This is my proposition: r'ID\s+([0-9]+)\s+linea+b\s+([0-9]+)\s+'
The problem is with linea+b where python does not accept + as a string, it analyzes it as a metacharacter.
You should add \ in front of + to recognize the symbol, not as an increment
r'ID\s+([0-9]+)\s+linea\+b\s+([0-9]+)\s+'

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

Regex clarification (both return true?) powershell [duplicate]

This question already has answers here:
How do I match an entire string with a regex?
(8 answers)
Regex.Match whole words
(4 answers)
Closed 5 years ago.
I'm trying to match a pattern in powershell, any 3 letters followed by any 2 numbers, example: abc00
Trying:
'abc00' -match '[a-zA-Z]{3}[0-9]{2}'
returns TRUE
but :
'abcdefg0000' -match '[a-zA-Z]{3}[_0-9]{2}'
also returns TRUE.
How do I limit it so if the string doesn't contain exactly 3 letters and 3 numbers, it returns false?
Thank you!

difference between 2 regex strings [duplicate]

This question already has an answer here:
Reference - What does this regex mean?
(1 answer)
Closed 4 years ago.
What is the difference in what these 2 are doing? Thx
var m = document.referrer.match(/\&cd=([\d]*)/);
and
var m = document.referrer.match(/cd=(.*?)&/);
Which one is more efficient and effective?
/\&cd=([\d]*)/ - matches any string starting with an "&cd=" followed by any zero or more decimal digits. The first capture group is the decimal digits.
/cd=(.*)&/ - matches any string starting with an "cd=" followed by zero or more characters up to and including the first "&". The first capture group is all characters between "cd=" and "&".
They are similar, but not equivalent. Which one you should use depends on your exact needs. Judging from your comment, it sounds like you want to use:
var m = document.referrer.match(/[?&]cd=(\d+)/);