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.
Related
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.
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 2 years ago.
Improve this question
I'm currently creating directories with a variable called currentDate.
I am trying to create the following directory:
business/bookings/15/06/2020 //3 levels down. the date is a level.
with business/bookings/currentDate
However, JavaScript and Firebase will interpret the '/' as another directory.
How could I solve this problem given that I'll get a variable that's always formatted this way?
A very simple substitution would be with escape/unescape, but nowadays I'd probably use encodeURIComponent/decodeURIComponent:
encodeURIComponent("business/bookings/currentDate")
"business%2Fbookings%2FcurrentDate"
decodeURIComponent("business%2Fbookings%2FcurrentDate")
"business/bookings/currentDate"
Short version: you can't.
The / character is not admitted in file (and directories) name. What you can do is to substitute the slash character with something else.
Hope this helps.
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 tried this : [fl]ady?[ing] ?[rb]ug!?
I know [fl]ad[y]?(ing)? ?[br]ug!? is an answer
Can this be solved using character sets only? Must match both.
ladybug
fading rug!
I believe this should work for you
[fl]ad(y|ing)\s?[br]ug?
Check out http://www.regexpal.com/
Using character sets only? So, it doesn't matter what other letter combinations it matches as well? Mmm. Then
[fl]ad[giny]+[\sbrug!]+
would do. See: https://regex101.com/r/FJWJyM/1
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 6 years ago.
Improve this question
I have a text input on my html page. When a user tries to add a new watch I want it to start with WATCH_XXXX (X's are whatever the user inputs). It has to start with WATCH_ all caps with the underscore. I've tried a lot of different ways but I keep getting the "please match the requested format" pop-up. This was the last one I tried -> required pattern="^WATCH_[a-z]". Am I even close to getting this right?
This regex ^WATCH_[a-zA-Z]+$ should work
<form>
<input required pattern="^WATCH_[a-zA-Z]+$"/>
<input type="submit"/>
</form>
Do all characters after "WATCH_" have to be letters? If not ^WATCH_.* may work better.
Tested here: https://regex101.com/#javascript
Also a great learning tool I use for Regex: http://regexone.com/
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 8 years ago.
Improve this question
Why is the webpage destroyed when I add a special character to the URL, especially the /?
For example,
myproject.loc/page1.php/
How can I solve this?
Try to encode your URL while you are creating it. If the URL is gonna be created by javascript encode it by following command:
encodeURIComponent('myproject.loc/page1.php/"?');
or if you are creating URL in PHP use this:
urlencode('myproject.loc/page1.php/"?');
However it's not recommanded to use some special characters in a website URLs which want to follow SEO
When you put a trailing slash after page1.php your browser interprets it as a directory and it ruins all of your relative paths.
If you really want the trailing slash after a filename you would need to use apache url rewrites.