This question already has an answer here:
Learning Regular Expressions [closed]
(1 answer)
Closed 2 years ago.
Fairly new to regex, looking to identify a user id pattern that is all alpha, is exactly 6 characters, and the second character is always a Z. Any help would be appreciated.
How about this regex:
\w(Z|z)\w{4}
Is this what you want?
As I understood you want something to detect something like this:
jZabcd
What you could do is something like this:
[A-Za-z][Z]([A-Za-z]{4})
Breakdown:
[A-Za-z] = detects all alpha big and small letters only once.
[Z] = checks if there is only a big "Z".
() = a group to make it easier.
{4} = checks if there is 4 times from what was infront of the 4.
[A-Za-z]{4} = checks if there are 4 letters from big A-Z and small a-z.
I hope this helps you out and please expand your question next time a little more.
Related
This question already has answers here:
What do ^ and $ mean in a regular expression?
(2 answers)
Closed 2 years ago.
I know there are similar question asked (might the same question here) but I can't seems to get my regex to work. I tried the answer there but didn't work which is below.
^[A-Z]{2}\d+
I'm trying to check if the country serial or organisation numbers start with specific two capital letters. For example BE0462427110 is from a Belgium company so all the org. numbers should start with BE. German once have DE and Italian once have IT in front.
So I tried below my own version as well.
^([BE]{2})([\d]{6,10})$
Below is a test block I use to extract the numbers from using regex. And the number is after "BEPC0 PARTS".
C0MMUNAUTE EUR0PEENNE 1 ExpCd1teur/Exp0rtateur (2) N0. BEPC0 PARTS
BE0462427110 Rue Chaum0nt(Herm) 4 D F BE 4480 Eng1s E D q 1jj -
Dest1na1re (8) N0, N M BUCHER 1ANDTECHN1K SA 7
After the above regex didn't work I tried another.
^([B][E])([\d]{6,10})$
So what am I doing wrong here ?
This anchors at the beginning and end of the string:
^([A-Z]{2})([\d]{6,10})$
You are looking for a pattern somewhere within a string, so you can anchor by word boundaries \b:
\b([A-Z]{2})([\d]{6,10})\b
This question already has answers here:
Getting the text that follows after the regex match
(5 answers)
Closed 4 years ago.
I have a line containing
[India,sn_GB] Welcome : { Name:{Customer1},Place:{Mumbai},}
I want to print the entire line after sn_GB] in splunk, which is
Welcome : { Name:{Customer1},Place:{Mumbai},}
I used the below regular expression:
(?<=sn_).*?$
But it prints, along with GB] like GB] Welcome : { Name:{Customer1},Place:{Mumbai},}.
In the word sn_GB, sn_ is constant and the rest two letter will vary, like GB, LB, KB, TB as such.
Please help me in correcting the regular expression.
Thanks
This will give the correct result in case sn_GB is constant.
(?<=sn_GB).*?$
If GB is not constant you can go for:
(?<=sn_...).*?$
I understand your question now.
Country codes are always 2 letters.
i'd use
(?<=sn_..\]\ ).*$
but you could use
(?<=sn_[A-Z]{0,5}\]\ \s*).*?$
(?<=sn_....).*$
is the simplest, as it will just grab 4 characters after, if it's always 2 letters for country code, and then a closing bracket and a space
This question already has answers here:
What's a Regex pattern for 3 consecutive digits increasing or decreasing
(3 answers)
Closed 6 years ago.
i would like to ask if it is possible to get a regex to check for subsequent alphabets or numbers in a string such as "abcd" or "1234" 4 characters in succession.
This is for password validation to check if a user is trying to enter a password like "abcd1234"
Thank You
Based on the answer Match increasing/decreasing sequences using regex, this pattern does close. Through programming you still need to get the first capturing group \1 and check whether its size is equal to 4. Here you need to set the multi line mode, to allow $ match the end of line.
This is because this regex is capturing all possible groups, however the groups you want has the length of 4, so it should not be a problem.
(?x)
(
(?:a(?=b|$))?
(?:b(?=c|$))?
(?:c(?=d|$))?
(?:d(?=e|$))?
(?:e(?=f|$))?
(?:f(?=g|$))?
(?:g(?=h|$))?
(?:h(?=i|$))?
(?:i(?=j|$))?
(?:j(?=k|$))?
(?:k(?=l|$))?
(?:l(?=m|$))?
(?:m(?=n|$))?
(?:n(?=o|$))?
(?:o(?=p|$))?
(?:p(?=q|$))?
(?:q(?=r|$))?
(?:r(?=s|$))?
(?:s(?=t|$))?
(?:t(?=u|$))?
(?:u(?=x|$))?
(?:x(?=z|$))?
[a-z]?
|
(?:0(?=1|$))?
(?:1(?=2|$))?
(?:2(?=3|$))?
(?:3(?=4|$))?
(?:4(?=5|$))?
(?:5(?=6|$))?
(?:6(?=7|$))?
(?:7(?=8|$))?
(?:8(?=9|$))?
\d?
)
On this link you can see the live regex: https://regex101.com/r/xxED4s/2
This question already has answers here:
What is the ultimate postal code and zip regex?
(20 answers)
Closed 9 years ago.
Am working on regular expression for following formats of zip in groovy
Includes a letter (L12345)
Includes a dash plus 4 more numbers (77056-1234)
Includes spaces (77056 1234)
I have this "^\d{5}(-\d{4})?\$" but its not matching the required formats. Could anyone please help me?
^\d{5}(?:[-\s]\d{4})?$
^ = Start of the string.
\d{5} = Match 5 digits (for condition 1, 2, 3)
(?:…) = Grouping
[-\s] = Match a space (for condition 3) or a hyphen (for condition 2)
\d{4} = Match 4 digits (for condition 2, 3)
…? = The pattern before it is optional (for condition 1)
$ = End of the string.
This is from the following question, hope it helps
regex for zip-code
For the optiona startingil letter use
[A-Z]?
to make the letter optional. {1} is redundant. (Of course you could also write [A-Z]{0,1} which would mean the same, but that's what the ? is there for.)
I think it should go after the ^ but haven't had a chance to test
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+)/);