Welcome to DU! The truly grassroots left-of-center political community where regular people, not algorithms, drive the discussions and set the standards. Join the community: Create a free account Support DU (and get rid of ads!): Become a Star Member Latest Breaking News General Discussion The DU Lounge All Forums Issue Forums Culture Forums Alliance Forums Region Forums Support Forums Help & Search

dogknob

(2,431 posts)
Sun May 4, 2014, 10:18 AM May 2014

It's 7:18am on Sunday morning. Wanna help me with a regular expression?

I know this is a total long-shot, but if anybody here would like to help me test the monster I wrote last night, then you can do it here:

http://regexr.com/38psn

I've spent a while trying to break it with mistakes one might make while naming a file that requires a naming convention (e.g. typos)

I'm using it to rat out bad filenames before I queue them up for transcoding in ffmpeg. The files are screened for bad extensions and bad MIME-types before they hit the expression, which I can't post here because of smilies.

There's info about the naming convention and what is supposed to match/not match at the link.

Thanks!

6 replies = new reply since forum marked as read
Highlight: NoneDon't highlight anything 5 newestHighlight 5 most recent replies
It's 7:18am on Sunday morning. Wanna help me with a regular expression? (Original Post) dogknob May 2014 OP
Not sure if it's critical ChromeFoundry May 2014 #1
Ooooo! dogknob May 2014 #2
EDITED: might be done with this now. dogknob May 2014 #3
Here is an alternative RegEx tester ChromeFoundry May 2014 #4
Dude! the colors! dogknob May 2014 #5
Got a bit more fat trimmed off of it. dogknob May 2014 #6

ChromeFoundry

(3,270 posts)
1. Not sure if it's critical
Sun May 4, 2014, 11:16 AM
May 2014

...I expanded the date parsing to match most valid dates....

http://regexr.com/38pt0

Note: it only checks for months between 01-12 and days between 01-31, last valid year is adjustable.

dogknob

(2,431 posts)
2. Ooooo!
Sun May 4, 2014, 12:01 PM
May 2014

Thanks!

I was using php checkdate() strings that make it through my original regex -- so no stuff like February 30...

But that's lovely... if I decide to change this from a php cron job to a .sh cron job! Wheee!

dogknob

(2,431 posts)
3. EDITED: might be done with this now.
Sun May 4, 2014, 05:18 PM
May 2014
http://regexr.com/38pua

I kept your improvements to the date group; nothing wacky will get in and it addresses my tendency to sometimes type '2104' .

checkdate() will kick out bogus dates.

I made what I think are some substantial improvements to the name and city groups. I also included a full description of what the regex is supposed to do (and not do) at the new link above.

Thanks so much for your help. This is the first time I've ever sat down and written a regex from scratch... and that website is the best one I have seen so far for testing.

ChromeFoundry

(3,270 posts)
4. Here is an alternative RegEx tester
Mon May 5, 2014, 03:54 PM
May 2014

It offers color coding and explanations for your expressions.
Offers a fairly decent debugger for an online solution.

http://regex101.com/r/xE3gZ3

Latest Discussions»Retired Forums»Website, DB, & Software Developers»It's 7:18am on Sunday mor...