I'm trying to get a correct regular expression for this problem:
I get a result from a webservice as a string that looks like this
tag: 54e16e66 (Mifare card standard)
I need to extract the 54e16e66 part (which is in hexa) only, regardless of what is before and after that part, i've tried several patterns, but I am not confident enough with regex and I can't seem to find a pattern that works.
Edit
"tag :" is aways present.
the hexa part I want to extract has variable length
what is after is a user comment, so it could be anything
Could someone help ? thanks in advance !
Michael
Assuming your string there is a good template, and assuming a posix regular expression parser,
/^tag: ([0-9a-f]{8})/
should work. If the length is variable, you would just change the {8} to {m,n}, where m and n are the minimum and maximum possible number of characters you can expect, respectively.
Related
I want a textbox to have a value between 0 and 24. However the below pattern does not seem to be working.
Regex regex = new Regex("^([0-9]|1[0-9]|2[0-4])$");
I'm not sure what WPF is, but this expression might likely validate 0-24:
^[0-9]$|^[1][0-9]$|^[2][0-4]$
In this demo, the expression is explained, if you might be interested.
Sorry I imagine this is a trivial one but I'm a rookie with regular expressions.
I want to replace every entry of number long in a document E.G
NumberLong(1000)
with
"1000"
using find and replace. IE keep the number and put quotations around it delete number long and brackets.
Could anyone tell me how this is done?
well this can help you to test your regular expresion based on lagunage
https://regexr.com/
I am looking for a regular expression for the following string:
SQL Err 100 on \TEST1.$PROD01.TEST.XYZ562
I want to search for anything with TEST*.$PROD*.TEST.XYZ*.
Can anyone help with the regular expression?
Basic effort was required, you could just tried it yourself and, I believe, find an answer on your own! For future needs, try site regex101.com, it helps to work with regulars.
So, you need to find a string containing TEST, then something, then . then $PROD value, again anything, and .TEST.XYZ, and finally anything, where $PROD is, as I understand, a variable without special characters (as [](){}.^\).
So, you get that:
TEST[^.]*\.<$PROD value should go here>[^.]*\.TEST\.XYZ
That should be enough. You will need to supstitude variable $PROD on your own, but I don't know your language, so I can't help with that part. Maybe something like this:
"TEST[^.]*\." + $PROD + "[^.]*\.TEST\.XYZ"
I am pretty new to the concept of regex and so I am hoping an expert user can help me craft the right expression to find all the matches in a string. I have a string that represents a lot of support information in it for vulnerabilities data. In that string are a series of CVE references in the format: CVE-2015-4000. Can anyone provide me a sample regex on finding all occurrences of that ? obviously, the numeric part of that changes throughout the string...
Generally you should always include your previous efforts in your question, what exactly you expect to match, etc. But since I am aware of the format and this is an easy one...
CVE-\d{4}-\d{4,7}
This matches first CVE- then a 4-digit number for the year identifier and then a 4 to 7 digit number to identify the vulnerability as per the new standard.
See this in action here.
If you need an exact match without any syntax or logic violations, you can try this:
^(CVE-(1999|2\d{3})-(0\d{2}[1-9]|[1-9]\d{3,}))$
You can run this against the test data supplied by MITRE here to test your code or test it online here.
I will add my two cents to the accepted answer. Incase we want to detect case insensitive "CVE" we can following regex
r'(?i)\bcve\-\d{4}-\d{4,7}'
Excuse my ignorance. My knowledge of regular expressions is extremely limited.
I have the following regular expression on a regular expression validator.
^(\d{1,3},?(\d{3},?){0,2}\d{3}|\d{1,3})$
It currently allows zero. I need to update it so that it does not allow a value of 0.
[Edit: Just to clarify, I would like it to exclude a value of zero rather than a singular "0" - thanks]
Any help would be greatly appreciated.
Thanks
zaps
You may be looking for something like this:
^[1-9]\d{0,2}(\d*|(,\d{3})*)$
0 is allowed by the second part of your regex. Change it to:
^(\d{1,3},?(\d{3},?){0,2}\d{3}|[1-9]\d{0,2})$
It makes sure that the first digit is non zero, when the total number of digits are less than or equal to three.
The regex still allows patterns like 000,000,000 and 000,123 To fix that you can change the first part of the regex to:
^([1-9]\d{0,2},?(\d{3},?){0,2}\d{3}|[1-9]\d{0,2})$
Or rewrite it as
^[1-9]\d{0,2}(,?\d{3}){0,3}$
This still allows 123,456789 and 123456,789. Let us change it to:
^[1-9]\d{0,2}(?:(,\d{3}){0,3}|(\d{3}){0,3})$
This will allow 123,456,789 and 123456789 but not 123,456789 or 123456,789