Regular Expression to check File type - regex

I am not an expert of Regexp literally but I got a regex which is for file matching in the source of one site, but it's not matching any file.
The expression is:
"^(([a-zA-Z]:)|(\\\\{2}\\w+)\\$?)(\\\\(\\w[\\w].*))+(.jpg|.JPG|.jpeg|.JPEG)$";
Is there any expression which matches or qualifies the test of above regexp.
Please Help.
Thank You

First thing is that it is in javascript so to test it on a tester, you need to replace \\ by a single \.
I'm not sure what you are trying to achieve but here are some examples of paths that will match your regex : https://regex101.com/r/Gso9Yx/2
Hope this helps...

Try simplifying it a bit.
[\w,\s-]+(\.jpe?g|\.JPE?G)$

Related

Regular expression everything after a link

I am a complete regular expression idiot, just keep that in mind :)
I am trying to create a regular expression that will match link:xxxxxx where everything after link: is a wildcard.
Can i just do link:* or am I totally misguided?
link:.* should work correctly.
. matches any character, and you want to repeat it "0 to unlimited" times so you add *.
If you're new to regex, a good way to learn it is by using regex101.
For your problem, you can check out this regex101 example
(Note that I have also added the g modifier, which means that you want to select all matches, not just the first matching line)

PERL Regex Negation Issue

I have written a regex to pick files of the format
(ABC.*\.DAT) in perl.
How to write a negation for the above regex?
I already tried expressions like (?!ABC.*)\.DAT or (?!(ABC.*\.DAT))
Any help is appreciated.
(?s:(?!ABC).)*\.DAT
You can try this negation based regex. See demo.
The above can be safely embedded into a larger pattern. For example,
/^(?:(?!ABC).)*\.DAT\z/s
If you are trying to match the whole input, and if ABC doesn't end with ., .D, .DA or .DAT, then the following will be faster:
/^(?!.*ABC)\.DAT\z/s

Perl Extended Regular Expressions - match with multiple question marks inside

I have got a weird thing to solve in perl using regular expressions.
Consider the strings -
abcdef000000123
blaDeF002500456
wefdEF120045423
All of these strings are matching with the below regular expression when I tried in C with pcre library support :
???[dD][eE][fF][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9]
But I'm unable to achieve the same in perl code. I'm getting some weird errors.
Please help with the piece of perl code with which these two things match.
Thanks in advance...
? is called quantifier that makes preceding pattern or group an optional match. Independently ? doesn't make any sense in regex and you are getting an error like: Quantifier follows nothing in regex.
Following regex should work for you in perl:
...[dD][eE][fF][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9]
OR even more concise regex:
.{3}[dD][eE][fF][0-9]{9}
Each dot means match any character.
PS: You probably are getting confused by shell's glob vs regex.
That looks more like a file system regex than a PCRE. In Perl, the ? is a quantifier, not a wild card. You may want to replace them with . to get the same results in anything Perl compatible.
I might use ...[dD][eE][fF][0-9]{9} or even replace the [0-9] with \d.
qr/[A-z]{3}def[0-9]{9}/i
should be the Perl Regex object used to validate the mentioned strings.
Regards

Regular Expression, match ${ANY_TEXT}

Can you please help me with reg ex. I cant make it :( I hate regex.
I need to match this string ${ANY_TEXT} .Exactly one "${" and exactly one closing tag "}".
Thanks a lot. :)
\$\{[^}]+\} will match it. It will match ${ABC} from ${ABC}}} as well. If you want to match complete lines, simply anchor the regular expression using ^\$\{[^}]+\}$.
A good site to learn regular expressions is http://www.regular-expressions.info/.
I suppose this covers all the texts.
/^\$\{[a-zA-Z]\}$/

Regular expression which will support forward slashes and fullstops

I need to find a regular expression which will support the following format
.[A-Z-a-z]/-
Would ^(\.[A-Za-z]\/-?)+$ work fine ?
i.e
.V/-.E/-
BUT THE - IS OPTIONAL
I trield ^(\.[A-Za-z]\/-)$
but i cannot seem to find a regular expression to support the - at the end
Could someone show me where i am going wrong please.
Thanks
If you want the regex to match the string ".V/-.E/-", you could use this:
^(\.[A-Za-z]\/\-?)+$
This should be as simple as adding a ? after the -. The whole regex would be ^\.[A-Za-z]\/-?$ (don't need the parens unless you are using backreferences)