The Cache: Technology Expert's Forum
 
*
Welcome, Guest. Please login or register. September 23, 2019, 06:51:14 AM

Login with username, password and session length


Pages: [1]
  Print  
Author Topic: regex thats giving me a headache  (Read 3738 times)
nutballs
Administrator
Lifer
*****
Offline Offline

Posts: 5627


Back in my day we had 9 planets


View Profile
« on: November 20, 2007, 04:18:03 PM »

Normally I am the goddam regex genious, but for some reason this is giving me a headache. I am trying to match content that has a long date like january 1st, 2007.

Code:
$regstr='#(?:January|March|April|May|June|July|August|September|October|November|December)\W+\d{1,2}.{1,4}\d{2,4}#is';
if (preg_match($regstr,$s) != 0) echo 'date';

pass it this and it matches:
Posted Tuesday, November 20th, 2007 at 11:44 am Filed Under Category: awesome dude!

Pass it this and it doesnt:
morgan 13 November 20th, 2007 4 at 7 4:16 pm 5 2a 3c Ahh… so your phone DOES support MP3
Logged

I could eat a bowl of Alphabet Soup and shit a better argument than that.
dimitry12
Rookie
**
Offline Offline

Posts: 27



View Profile
« Reply #1 on: November 21, 2007, 12:30:03 AM »

Code:
if("morgan 13 November 20th, 2007 4 at 7 4:16 pm 5 2a 3c Ahh. so your phone DOES support MP3" =~ m/(?:January|March|April|May|June|July|August|September|October|November|December)\W+\d{1,2}.{1,4}\d{2,4}/is){
    print "pass!\n";
}else{
    print "no!\n";
}'

prints "pass!"
Logged
nutballs
Administrator
Lifer
*****
Offline Offline

Posts: 5627


Back in my day we had 9 planets


View Profile
« Reply #2 on: November 21, 2007, 09:25:14 AM »

err... what the fuck is that magic syntax you're using?

hmm. it passes? I wonder if those spaces are actually spaces. Obviously when I copy paste them into the forum they probably get converted somewhere along the lines. I gotta check that out.

thanks for testing it.
Logged

I could eat a bowl of Alphabet Soup and shit a better argument than that.
perkiset
Olde World Hacker
Administrator
Lifer
*****
Offline Offline

Posts: 10096



View Profile
« Reply #3 on: November 21, 2007, 01:33:12 PM »

Cripes Dim, I can't find that syntax anywhere - is that "=~" equal to a regex? I'm not at my machine so I cant test...

Feckin' learn something every day...

short outline please:


Logged

It is now believed, that after having lived in one compound with 3 wives and never leaving the house for 5 years, Bin Laden called the U.S. Navy Seals himself.
dimitry12
Rookie
**
Offline Offline

Posts: 27



View Profile
« Reply #4 on: November 21, 2007, 02:53:08 PM »

it's perl, sorry Smiley
Logged
chide
Rookie
**
Offline Offline

Posts: 20


View Profile WWW
« Reply #5 on: November 21, 2007, 04:08:39 PM »

Yummy perl Smiley
Logged
Pages: [1]
  Print  
 
Jump to:  

Perkiset's Place Home   Best of The Cache   phpMyIDE: MySQL Stored Procedures, Functions & Triggers
Politics @ Perkiset's   Pinkhat's Perspective   
cache
mart
coder
programmers
ajax
php
javascript
Powered by MySQL Powered by PHP Powered by SMF 1.1.2 | SMF © 2006-2007, Simple Machines LLC
Seo4Smf v0.2 © Webmaster's Talks


Valid XHTML 1.0! Valid CSS!