Regular Expression for set of number and repeated words - regex

I need to find out the files similar to this
1234-JOHN-ebook.pdf
98749-RAJ-test.epub
Is there any regular expression that matches this format?

if the capitalization will allways be as in your examples then: \d+-[A-Z]+-[a-z]+\.[a-z]+
if not, this will do \d+-\w+-\w+\.\w+.
please notice you might need to escape the dashes (\-)

Related

Regex Expression Query

I have data as
CVE-2011-0573,
CVE-2011-0606,
(CVE-2011-0565)
CVE-2011-0598,
CVE-2011-0593.
((CVE-2011-0593.)
Could you please help me writing RegEx so I only get ABC-####-#### ? The last four digit may vary, so it can have e.g. three or five digits, but most likely not more than ten. Also the expresion may contain some spaces in the end, so those need to be removed as well.
You can use this regex for matching:
[A-Z]{3}-[0-9]{4}-[0-9]{3,10}
If you have multiline flag available then use
/^[A-Z]{3}-[0-9]{4}-[0-9]{3,10}$/mg

Exclude file extensions regular expression

I have a regular expression for a URL check written in VBScript.
regLinkEx.Pattern = "(^|[\s>='])((((http|ftp|https):\/\/)?([а-яёa-z\-_]{1,})(\.[а-яёa-z\-_]{2,})*(\.([^exe|EXE|xml|XML|dll|DLL|ini|INI|bat|BAT|dat|DAT|bin|BIN|mif|MIF|txt|TXT|]){2,}|рф)+)([\w\-\.,#?^=%&:/~\+#]*[\w\-\#?^=%&/~\+#])?)"
I exclude file extensions that I need, but I also want to match letters from a to z
this is the part where I want, and I'm trying to do like this...
(\.[a-z]*([^exe|EXE|xml|XML|dll|DLL|ini|INI|bat|BAT|dat|DAT|bin|BIN|mif|MIF|txt|TXT|]){2,}|рф)+)
...but it doesn't work.
Can anyone help me?
In a Regular Expression, square brackets indicate a match for "any character within". So, for example, the regular expression [^exe|EXE|xml]{2,} matches any two characters that aren't in [exEXml].
If you are looking to exclude certain file extensions, use negative lookahead. Since negative lookaheads are zero-length, you can string them together to create behavior like "X followed by none of the following: EXE, XML, DLL" (the regex for this would be X(?!EXE)(?!XML)(?!DLL)).
As a side note, VBScript fully supports negative lookahead, does not support negative look behind (a significantly more complex and intensive behavior).

Creating a regular expression to match words of varying lengths

I'm writing a regular expression to parse a logfile and I'm having trouble figuring out how to establish a range(?) of sorts for a particular expression. In this case specifically, my logfile contains various severities:
(['EMERG','ALERT','CRIT','ERR','WARNING','NOTICE','INFO','DEBUG'])
I'm basically wondering how I'd write regular expression to match all of those. I understand most digit work, but characters are posing difficult issues for me.
this regex will match all these entries: [A-Za-z]{1,}
basically it says match all patterns that have only chars from A to Z or a to z with the lenght of at least one char.
for more information see this: regex cheat-sheet
and try your regex here: http://gskinner.com/RegExr/

Regular expression to replace shortest match

my string is like this
sfdfdsfdsfstart112matlab2336endgfdgdfgkknfkgstart558899enddfdsfd
how can we replace part of a string such a way that the result will be
sfdfdsfdsfgfdgdfgkknfkgdfdsfd
i.e bolded content need to be removed.
You need to use non-greedy matching:
start.*?end
Use replacement function with this regex /start.+?end/g which will match the bold parts of your string. The g part of the regex means globally, and might need to be implemented differently depending on the language you use.
The key here is to use ? which turns on un-greedy matching. That means the match consumes the minimum amount of characters rather than the maximum, so will match from the start to the next rather than the last end
start[1-9]+end
if you need to have numbers between words

is it the right reqular expression

i have following regular expression but it's not working properly it takes only three values after # sign but i want it to be any number length
"/^[a-zA-Z0-9_\.\-]+\#([a-zA-Z0-9\-]+\.)+[a-zA-Z0-9]{2,4}$/"
this#thi This is validated
this#this It is not validating this expression
Can you please tell me what's the problem with the expression...
Thanks
If you want your regex to match "any number length" then why are you using {2,4}?
I think a better example of the strings you're trying to match might give others a better idea of what you want, because based on your regex it is a bit confusing what you're looking for.
Try this:
^[a-zA-Z0-9_.-]+#([a-zA-Z0-9-]+\.)+[a-zA-Z0-9]{2,4}$
The main problem is that you didn't escape the dot: \.. In regular expression the dot matches everything (mostly), making your regex quite liberal.