I am looking for a reg ex to parse codes that look like this:
TEDL 9V1J 5K1Y EQFF NSA1 CF4T 8NQU UZL1
I have this regex, which works, but I would be grateful to understand how to make it more concise.
[A-Z0-9]{4}\s[A-Z0-9]{4}\s[A-Z0-9]{4}\s[A-Z0-9]{4}\s[A-Z0-9]{4}\s[A-Z0-9]{4}\s[A-Z0-9]{4}\s[A-Z0-9]{4}
Thanks.
Add this \s[A-Z0-9]{4} regex into a non-capturing group and add {7} after that to make the pattern to repeat for exactly 7 times.
^[A-Z0-9]{4}(?:\s[A-Z0-9]{4}){7}$
OR
\b[A-Z0-9]{4}(?:\s[A-Z0-9]{4}){7}\b
DEMO
You can use refactory your regex to:
\b((?:[A-Z0-9]{4}(?: |$)){8})
RegEx Demo
(([A-Z0-9]{4})\s){7}([A-Z0-9]{4})
Related
I have a string
K9908098F, G2342D34324/ 234234323, 234-234-234; R324234
How to catch only 234234323 and 234-234-234 in VBA?
This [\d-]+ pattern grabs extra pieces
You are pretty close, just need to add borders: \b[\d-]+\b
Regex demo and explanation
Give this a try:
(\w+),\s+([\w-]+);
This will capture 234234323 in group 1 and 234-234-234 in group 2.
Not too elegant though but would work. Just a small addition to your regex.
[\d-]+[,;]
You can try this too,
[-\d]+(?=[;,. ])
Demo
I have two string in which I have to sorten urls. I want a regex pattern to extract them
https://l.facebook.com/l.php?u=http%3A%2F%2Febay.to%2F2EyH7Nq&h=ATNHM5kACc4rh_z68Ytw__cNCzJ63_iPezd_whc0PjcsN4qj1PfdJgFXyrOKM3-biqPm7eAXTOc5LD6r-7JXhRsqsqEHUs0jaJkjvm_QWf6sqbHQmS63q6P0_NcQoUa86Az5EttNT9xJb_evKBaiFxW7e7v2afJQn2zNxz5lQ8xgxhMcEFuJ3hUiSYUMEemKFB2LSIgAZFibRv4GeRrTk8hxFaArkBuAhQaXQFd4jX-aQuUYhjD0ErV5FY-D4gFMpb0lFCU7SyBlRpkUuOcHVjwjxN-_g6reMYwo8loAJnJD
/redirect?q=http%3A%2F%2Fgoo.gl%2FIW7ct&redir_token=PV5sR8F7GuXT9PgPO_nkBFLABQx8MTUxNjA3OTY5MEAxNTE1OTkzMjkw&v=7wmIyD1fM4M&event=video_description
Output will be from 1st and 2nd link:-
http%3A%2F%2Febay.to%2F2EyH7Nq
http%3A%2F%2Fgoo.gl%2FIW7ct
Please help me out.
I have already used:-
(http|https).*?&
but its not working on first url.
You can try this:
=(https?[^&]*)
Demo
If lookbehind is possible in your flavour of regex then you may try this as well which will ensure to not capture the equal sign:
(?<=)(https?[^&]*)
Demo 2
Try this regex !
I am also attach the output of the regex through regex101.
http%3A%2F%2F(.*)%2F(.*[^&])(?=&)
You can use this pattern to only capture goo.gl and ebay.to links:
(http%3A%2F%2F(ebay\.to|goo\.gl)%2F[^&]*)&
Demo
Sample: AAAATGCCCTAAGGGATGTTTTAGAAA
I want to capture all string with these criteria:
Start: ATG
Follow by 3x characters of sets: A or C or G or T
End: TAA or TAG or TGA
Such as: ATGCCCTAA, ATGTTTTAG
I had a regular expression here: /[ACGT]*((ATG)(([ACGT]){3})+(TAA|TAG|TGA))[ACGT]*/g, but it only match the last ATGTTTTAG not ATGCCCTAA. I don't know why ?
Please help me write pattern that match both ATGCCCTAA and ATGTTTTAG.
Here is online example:
https://regex101.com/r/iO8lF9/1
This regex works well /(ATG(?:A{3}|C{3}|G{3}|T{3})(?:TAA|TAG|TGA))/g
as you can see here: https://www.regex101.com/r/gZ0zA9/2
I hope it helps
Using back-reference you can shorten your regex as this:
ATG([AGCT])\1{2}(?:TGA|TA[AG])
RegEx Demo
It matches [AGCT] after ATG and groups it as captured group #1. Next we match \1{2} to make sure same letter is repeated 3 times.
try...
^ATG[AGCT]{3}(TAA|TAG|TGA)$
I use this pattern and it works, thank all you for helping me.
/(ATG(:?A{3}|C{3}|G{3}|T{3})(:?TAA|TAG|TGA))/g
I need to match only first two files, out of four files listed below:
ABD_DEF_GHIJ_20150611
ABD_DEF_GHIJ
ABD_DEF_GHIJ_FX_20150611
ABD_DEF_GHIJ_FX
I am using reg ex - ABD_DEF_GHIJ(_\d{8}|\b) and it's working fine. I would like to know if my solution is ok or there is any better alternate solution.
You could use a negative lookahead which will exclude those having _FX following the initial alpha string
^ABD_DEF_GHIJ(?!_FX)(?:_\d{8})?$
see example here
Use anchors and make the number part as optional.
^ABD_DEF_GHIJ(?:_\d{8})?$
DEMO
seems like you don't want to include files with FX, use negative look ahead, you can also append the optional (_\d{8})? if you think it's necessary
^ABD_DEF_GHIJ(?!_FX)
DEMO
DEMO 2
Try this RegEx:
ABD_DEF_GHIJ(?!_FX_?)(_\d{8})?
On regexpal.com:
This also works:
\bABD_DEF_GHIJ(?!_FX_?)(_\d{8}|\b)
I am trying to find a single-line string using the following regex:
=949.+\$h[^1]\$.+
However, the \$h[^1]\$ string can contain 10 and 11 in addition to a 1. I want to find the tens and elevens but NOT the ones.
So I want to find:
$h10 and $h11 but NOT $h1
Thoughts?
to clarify, I'd like it to find 2,3,4,5,6,7,8,9,10,11 but not 1
You can use this:
\$h(2|3|4|5|6|7|8|9|10|11)
DEMO:
http://regex101.com/r/lX4mS5
If you want to match everything except $h1, you can use a negative look-behind, like this:
\$h[\d]{1,2}(?<!(\$h1))
DEMO:
http://regex101.com/r/bS8mA2
Another option (without looking around):
\$h([2-9]|\d{2,})
Debuggex Demo