Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 1 year ago.
Improve this question
I need to validate the filenames before a upload. I thought regex would be the perfect solution for that, but I don't have a clue of regex.
The filenames have all a specific structure.
What I tried myself is: /([-\d]{2,})_([a-zA-Z\d]+)/, but this will only match the first numbers and the first tag in the filename.
Example: 100_test-tag1-tag2.gif or 100_test_tag1-tag2.gif
The files have to start with a number and after the number should be a underscore. After that it should at least have one part with a tag. The tags can be separated by a underscore or a hyphen. The tags can occur an infinite number of times. The file ending should be .gif.
Your attempt is almost complete:
Try this:
/([-\d]{2,})_([a-zA-Z\d]+)([_-][a-zA-Z\d]+)*\.gif/
I added this:
([_-][a-zA-Z\d]+)*
which matches an _ or - followed by a tag zero ore more times.
And
\.gif
which matches the trailing .gif.
Related
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 3 months ago.
Improve this question
Having a hard time with Regex.
What would be the regex for finding a file name with variable in between them?
For eg:
File name : DON_2010_JOE_1222022.txt
In the above file name the words DON, JOE and the format .txt will remain constant. Rest numbers might change for every file. There could be characters as well instead of numbers in those two places.
What im looking for is basically something like DON_*_JOE_*.txt with * being whatever it could be.
Can someone please help me with this?
I tried DON_*_JOE_*.txt and obviously it did not work.
DON_(?<firstString>.*)_JOE_(?<secondString>.*).txt
You can use this. To access the specific group, you can use matcher.group("firstString").
In JavaScript:
"DON_2010_JOE_1222022.txt".match(/DON_.+_JOE_.+\.txt/)
whatever it could be
It is .+ except new lines.
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 2 years ago.
Improve this question
So i want to make a regular expression to validate times between 12:00 and 22:00 but i cant get my head around making expressions and cant find any examples online that i can just swap out examples of. Can anybody help me?
You can use the following regular expression:
^((1[2-9]|2[0-1]):[0-5][0-9]|22:00)$
This is how it works:
^ and $ match start and end of string, and they are there to prevent matching also 112:009 for example (which contains 12:00).
[2-9] matches numbers between 2 and 9, and (a|b) would match either a or b.
Debuggex Demo
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 4 years ago.
Improve this question
Say I have a regex pattern like this:
/^\*HELLO\*/
Just looking for the string "*HELLO*". But then I completely want to change it up so I do this:
/^\*&$&^*2#H\*/
Now I'm looking for the string "*&$&^*2#H*".
How should I change my regex pattern to check for such a complex string with all those different characters?
You should escape the special characters in your pattern, wich are used as tokens by Regex, such as *,^ and $. Or you will end up with an error claiming about a wrong pattern in your regex.
This is how should be your regex: /\*&\$&\^\*2#H\*/.
Furthermore if you are searching for the string with .indexOf() or .includes() methods, you can just pass the string as it is.
str.indexOf("^\*&$&^*2#H\*");
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 5 years ago.
Improve this question
I have a sentence example: I am just one man I', trying to capture am just on with the following regex, but it also captures I which is not what I need.
(?=I).*(?= man)
The result is: I am just one
I don't want extra capturing groups, only the full match which should be am just one.
change the first positive lookahead to a negative (?!I). This won't capture I
(?!I).*(?= one)
By saying look and match anything except I
(?=[^I ]).*(?= man)
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 8 years ago.
Improve this question
I want a regular expression that checks if a string contains only the allowed characters. The allowed characters are alphanumeric and the special characters (),#\/\-. I used this expression, and it is working fine.
/^([A-Za-z0-9 .(),#\/\-]*)+$/
Now I don't want the string to start with space or any disallowed characters, but it can have space in the middle. Also, the string may not consist of only special characters; it should have at least one alphanumeric character.
Can someone help me understand how to adapt the regex I am using to check these additional constraints?
^(?=[a-zA-Z0-9])([A-Za-z0-9 .(),#\/-]*)+$
This should do it.