I have a list:
gform_18
gform_27
gform_23
gform_11
Let's say I'd like my regex to match "gform_" when it's followed by numbers 18, 23, and 11. 27 has to be excluded.
What would be the right regex for that ?
In case it's important: I need this regex to run in Google Tag Manager with a "matches Regex" condition.
Thanks a lot.
I made some search but it's not answering my question properly because the usecases I've found are different.
Use an alternation:
gform_(18|23|11)
Related
Let's say I have these three names
John Doe (p45643)
Le'anne Frank
Molly-Mae Edwards
I want to match
1) John Doe
2) Le'anne Frank
3) Molly-Mae Edwards
The regex I have tried is
(^[a-zA-Z-'^\d]$)+
but it isn't working as I am expecting.
I would like help creating a regex pattern that:
Matches a name from start to finish, and cannot contain a number. The only permitted values each "name" can contain is, [a-zA-Z'-], so if a name was
J0hn then it shouldn't match
If I understood correctly your question, then you have a minor errors in your regex:
(^[a-zA-Z-'^\d]$)+
^-------^------Here
The - pointed above should be escaped or moved to the end since it works as a range character. The + is marking the group as repeated.
You can use this regex instead (following your previous pattern):
(^[a-zA-Z'^\d -]+$)
Regex demo
Update: for your comment. If you want to match separately, then you can use:
(\b[a-zA-Z'^\d-]+\b)
Regex demo
And if you only want to match string (not numbers), then you can use:
(\b[a-zA-Z'-]+\b)
Regex demo
You are using the anchors incorrectly. Based on the modifier it can match the whole string or a single line.
Try
/^[a-zA-Z'-]+$/
Thanks to #Djory Krache
The query I was looking for was
(\b[a-zA-Z'-]+\b)
I'm hoping someone can help with some regular expression. I'm trying find instances where two patterns exist in a string (I think I'm saying that right).
Here is my test string:
{"eventid": 2121, "username":"FRED", "starttime": "1550243080", "newprocessname": "C:\\Windows\\System32\\wbem\\WmiPrvSE.exe", "parentprocessname": "C:\\Windows\\System32\\svchost.exe"}
I want to be able to search based on one or more criteria. The problem I have is when multiple criteria is provided. For example, the following seems to match if username is good or newprocessname is good whereas I want it to match only if both are good.
("username"\s*:\s*"(.*?)FRED(.*?)")|("newprocessname"\s*:\s*"(.*?)WINDOWS(.*?)")
I think my patterns are right, but how do I return a result only if both patterns match?
I hope I'm explaining this correct???
Thank you!
Jon
If you're using a regex library that supports lookaheads you can use this regex:
^(?=.*"username"\s*:\s*"([^"]*)FRED([^"]*)")(?=.*"newprocessname"\s*:\s*"([^"]*)WINDOWS([^"]*)")
It looks for both the username and newprocessname tags at the same time (as the lookaheads don't consume any characters). Note that you need to change .*? in your regex to [^"]* otherwise you can match text further into the string than the actual value associated with the tag name.
Demo on regex101
I use load runner 12.5 to record script . I want to extract a value in response script and pass it to other so I want to find 17821107849674 in script with regular expression. what should I do?
.
.
.
AdfLoopbackUtils.runLoopback(
9,
'_afrLoop',
'17821107849674',
'_afrWindowMode',
'Adf-Window-Id',
'_afrPage',
'',
'w0',
';EBOXPORTALID=3fUCuSHtu2lAMvjhIqj5GMCRNrUTXZ_E0w-nQGzQxolJ4T38oItW!-939378123',
'!',
false,
Loadrunner should be using PCRE as the default regex engine.
So you could look for 14 digits surrounded by word boundaries \b:
\b(\d{14})\b
Or more precisely, look for 14 digits and lookaround for single quotes :
(?<=\')(\d{14})(?=\')
To be even more precise and check if it's followed by that _afrWindowMode:
((?<=\')[0-9]+(?=\',\s*\'_afrWindowMode\'))
Tell us more about the pattern? Is it always the third element in the set? Is it always preceded by "'_afrLoop'," or followed by ",'_afrWindowMode'?"
You potentially have several paths to collect the value, but understanding the patterns involved helps
I need to use regex match expression to find part of a file name.
eg file name is ABC01-001-M-001_0.dwg
I need to match the first digit after the underscore (this is the revision number of the drawing file name)
In this case with the example it would match the 0
Can anyone please advise the regex for this?
Many thanks.
pushpraj answer is almost correct. I take it you dont want to see the underscore.
so (?<=_)(\d+) would be the correct choice. The (?<=_) says, that the underscore have to be in front of your desired pattern but not included.
Demo: https://regex101.com/r/kH1nE2/2
I think this should be pretty simple.
_(\d)
online demo https://regex101.com/r/kH1nE2/1
in case you expect more digits you can use the following
_(\d+)
note "+" which will match 1 or more digits after underscore
In this case regex is not even needed.
$n = "ABC01-001-M-001_0.dwg";
Echo intval(explode("_", $n)[1]); // 0
https://3v4l.org/fBXc5
It seems you are looking for a javascript solution?
var n = "ABC01-001-M-001_0.dwg";
var int = parseInt(n.split("_")[1]);
Not sure it actually works because I'm not doing writing in javascript but ^^ is what I could google about the functions.
Maybe works, maybe not.
It seems to work :-)
https://jsfiddle.net/w9x7d40f/
is it possible with regex to match a particular sequence repeating it self rather than number of letters? I would like to be able to match cn.cn. or ti.ti. or xft.xft. but not vv.pp. or aa.bb. and I do not seam to be able to do that with (\w\w.)+ opposed to \w+.\w+. in the first case I want in fact to use only one occurrence, like cn. or ti. in the second I want to keep v.p. or a.b.
thanks for any help.
Depending on your flavor of regex, you can use backreferences in your regex to match an earlier group. Your question title and question body disagree, however, on what exactly is supposed to be matched. I'll answer in Python as that's the flavor I'm most familiar with.
# match vv.pp., no match cn.cn.
re.match(r"(\w)\1\.(\w)\2\.", some_text)
# match cn.cn., no match vv.pp.
re.match(r"(\w{2})\.\1\.", some_text)