I'm new on the regex and I'm trying to find all the files inside some folders.
The files name are like this:
B11102R-300x1608.jpg
AT5020.jpg
AT5045-1-1024x1024.jpg
ABBIGLIAMENTO-324x130.jpg
etc...
What I would like to is find all the files that have the images size append to it... so I'm trying to create a regex to show only file that contains this pattern -300x1608.jpg where of course the numbers are random.
I tried with this regex -(.*?). but it doesn't solve the problem since it select from the first - and thus it can find similar false positive match!
Could you help me?
regards,
Luca
You could force a search for numbers:
^.*-\d+x\d+\.jpg$
See the demo.
^ - Start string ancor.
.* - Any character other than newline zero or more times.
- - A literal hyphen.
\d+x\d+ - At least a single digit, a literal x and again at least a single digit.
\. - A literal dot (need to be escaped).
jpg - Literally match 'jpg'.
$ - End string ancor.
Related
I'm trying to extract a query from a string, I tried writing my own function, but it doesn't match my needs totally.
What I need is:
www.website.com/8056432988456?id=5, I need 8056432988456, with or without the / i.e. preceding a ?.
This is the regex I made for it : (?<=\/)(.*?)(?=\?)|(?<=\?)
Can someone help me out?
You can use
(?<=\/)\d+(?=(?:\/?\?.*)?$)
See the regex demo.
Details:
(?<=\/) - there must be a / immediately on the left
\d+ - one or more digits
(?=(?:\/?\?.*)?$) - immediately on the right, there must be an optional occurrence of:
(?:\/?\?.*)? - an optional occurrence of an optional /, then ? and then any zero or more chars other than line break chars as many as possible
$ - end of string.
I'm trying to develop a regex that partially matches a certain branch of a path. Not before and not deeper than that level. For example:
/path - no match
/path/subpath - no match
/path/subpath/XYZ-123/subpath - no match
/path/subpath/XYZ-123 - match
So far, I have the following
^\/path\/subpath\/.*$
However, this obviously also matches for /path/subpath/XYZ-123/subpath which I would like to exclude as well. Note that the path contains characters, numbers and special characters.
You may use
^\/path\/subpath\/[^\/]*$
See the regex demo.
The regex will match
^ - start of a string
\/path\/subpath\/ - /path/subpath/ string
[^\/]* - 0 or more chars other than /
$ - end of string.
I want to use Regex to find a line containing a particular pattern.
The pattern should be a string starting with 2 characters (a-zA-Z0-9) followed by a dash then either "FAL" or "SAL" and does not include the term "OJT" at all.
Just want to make sure I have the right or am I missing something as it doesn't appear to work as expected
^[a-zA-z0-9]{1,2}(?=.*?\-SAL|-FAL\b)((?!OJT).)*$
You may use
^[a-zA-Z0-9]{1,2}(?!.*OJT).*?(?:-SAL|-FAL)\b.*
See the regex demo
Details
^ - start of string
[a-zA-Z0-9]{1,2} - one or two alphanumeric chars
(?!.*OJT) - any 0+ chars, as few as possible, followed with OJT char sequence should not appear immediately to the right of the current location
.*? - any 0+ chars other than line break chars as few as possible
(?:-SAL|-FAL)\b - -SAL or -FAL not followed with a word char
.* - the rest of string.
See the regex graph:
I want to find any kind of uuid or random generated text in a url path and replace it with <random>. Examples :
/test/ajs1d5haFkajs1dhasdd2as345sdAS3+Ddas9 = /test/<random>
/test/akKd9Ja3/ajs1d5haFkajs1ddasd623ha5sdAS3Ddas9=/30 = /test/<random>/<random>/30
/test/akKd9Ja3/Example-ASDAdddasd-108174.js = /test/<random>/Example-108174.js.
/test/akKd9Ja3-ASj83asj-dask92qwe_ke = /test/<random>
I'm looking for a solution that will match on a string:
starting with / AND
end with / or $
contain [0-9] AND
contain [a-z] OR [A-Z]
CAN contain -, =, _, +, \s (spa
DOES NOT contain an extension i.e .<something>
7 char and longer {7,}
This is what I used so far :
/[a-zA-Z0-9-=_+\s]{30,}
This works for most cases since uuids are often longer than 30 char. But I don't catch the small ones i.e /5c88148/ or /6qdkKdk5/. I also match on things like Example-ASDAddasd-108174.js.
Update - In case you want match must contain at least one digit.You can use this.
(?<=\/)(?=[\w-+=\s]+[0-9])[\w-+=\s]{7,}(?![.])(?!\.)(?=\/|\n)
Demo for update
You can try this.
(?<=\/)[\w-+=\s]{7,}(?!\.)(?=\/|\n)
Explanation
(?<=\/) - Positive look behind. Matches '/'.
[\w-+=\s]{7,} - Matches any word character, -,+,=, and space 7 or more time.
(?!\.) - Negative look ahead. Do not match ..
(?=\/|\n) - Positive look ahead. Matches '/' or '\n'(New line).
Demo
I'm having issues with the validation of the chilean RUT/RUN with a regex expression in PCRE. I have the next regular expression but sadly can't make it work:
\b[0-9|.]{1,10}\-[K|k|0-9]
I need help to see what is wrong with the code. The application I need to use only uses PCRE.
Thank you.
You may use
^(\d{1,3}(?:\.\d{1,3}){2}-[\dkK])$
to match and capture (that is not usually necessary, but your app requires a capturing group to extract its contents) a whole string that matches the pattern. See the regex demo.
To match shorter strings that match this pattern inside a larger string, you may remove ^ and $ (see demo) or use \b word boundaries instead (see this demo).
Details:
^ - start of string
\d{1,3} - 1 to 3 digits
(?:\.\d{1,3}){2} - 2 sequences of a literal . and 1 to 3 digits
- - a hyphen
[\dkK] - a digit, k or K.
$ - end of string.
As they sometimes omit the dots, I used this one:
^(\d{1,2}(?:[\.]?\d{3}){2}-[\dkK])$
Details:
^ - start of string
\d{1,2} - 1 or 2 digits
(?:[.]?\d{3}){2} - 2 sequences of an optional '.' and 3 digits
- a hyphen
[\dkK] - a digit, k or K
$ - end of string
1234567-k OK
12345678-k OK
1.234.567-k OK
12.345.678-k OK
known issue:
12.345678-k and 12345.678-k still OK and I do not like this :(
You need to change to ^(\d{1,3}(?:\.\d{3}){2}-[\dkK])$ to capture only 2 sequence of 3 digits after the first sequence of 1-3 digits.
please consider being more specific in the REGEX build, since it matched wrong numbers, such as 17.87.335-2. Also the included one did't match formats without the dots or the hyphens.
Please consider using the following format: \b(\d{1,3}(?:(.?)\d{3}){2}(-?)[\dkK])\b
Modified prior version to try the other formats: https://regex101.com/r/2Us0j6/9