REGEX question

This is a discussion on REGEX question within the PHP Language forums, part of the PHP Programming Forums category; I'm very new to Regex, I've been strugling a lot to use it, hard to find good material :) ...


Go Back   Usenet Forums > PHP Programming Forums > PHP Language

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 03-07-2008
Feijó
 
Posts: n/a
Default REGEX question

I'm very new to Regex, I've been strugling a lot to use it, hard to
find good material :)

I just need to find all matchs for something like this:
D00:00:00:00

leter D, following by 4 sequences of 2 digits separated by : (2
points)

How can I do that?

There is any software for windows that helps us newbies learn that
fabulous language?


Thanks!!
Feijó
Reply With Quote
  #2 (permalink)  
Old 03-07-2008
Tim Roberts
 
Posts: n/a
Default Re: REGEX question

Feijó <afeijo@gmail.com> wrote:
>
>I'm very new to Regex, I've been strugling a lot to use it, hard to
>find good material :)
>
>I just need to find all matchs for something like this:
> D00:00:00:00
>
>leter D, following by 4 sequences of 2 digits separated by : (2
>points)
>
>How can I do that?


"D[0-9]{2}:[0-9]{2}:[0-9]{2}:[0-9]{2}"
--
Tim Roberts, timr@probo.com
Providenza & Boekelheide, Inc.
Reply With Quote
  #3 (permalink)  
Old 03-07-2008
Rik Wasmus
 
Posts: n/a
Default Re: REGEX question

On Fri, 07 Mar 2008 03:39:26 +0100, Feijó <afeijo@gmail.com> wrote:
> There is any software for windows that helps us newbies learn that
> fabulous language?


http://www.regular-expressions.info/

A while back I used the .Net Regex Workbench. Can't seem to find a place
to download it from now though...
--
Rik Wasmus
Reply With Quote
  #4 (permalink)  
Old 03-07-2008
Feijó
 
Posts: n/a
Default Re: REGEX question

Him Tim, Thanks!

Thats wierd, your code works on my pspad regex search (if found a
example I type in my source-code), but when I run over php, this error
is returned:

Warning: preg_match_all() [function.preg-match-all]: Delimiter must
not be alphanumeric or backslash

You know why?


On Mar 7, 3:52 am, Tim Roberts <t...@probo.com> wrote:
> Feijó <afe...@gmail.com> wrote:
>
> >I'm very new to Regex, I've been strugling a lot to use it, hard to
> >find good material :)

>
> >I just need to find all matchs for something like this:
> > D00:00:00:00

>
> >leter D, following by 4 sequences of 2 digits separated by : (2
> >points)

>
> >How can I do that?

>
> "D[0-9]{2}:[0-9]{2}:[0-9]{2}:[0-9]{2}"
> --
> Tim Roberts, t...@probo.com
> Providenza & Boekelheide, Inc.

Reply With Quote
  #5 (permalink)  
Old 03-07-2008
Rik Wasmus
 
Posts: n/a
Default Re: REGEX question

On Fri, 07 Mar 2008 11:33:00 +0100, Feijó <afeijo@gmail.com> wrote:
> On Mar 7, 3:52 am, Tim Roberts <t...@probo.com> wrote:
>> Feijó <afe...@gmail.com> wrote:
>>
>> >I'm very new to Regex, I've been strugling a lot to use it, hard to
>> >find good material :)

>>
>> >I just need to find all matchs for something like this:
>> > D00:00:00:00

>>
>> >leter D, following by 4 sequences of 2 digits separated by : (2
>> >points)

>>
>> >How can I do that?

>>
>> "D[0-9]{2}:[0-9]{2}:[0-9]{2}:[0-9]{2}"

>
> Thats wierd, your code works on my pspad regex search (if found a
> example I type in my source-code), but when I run over php, this error
> is returned:
>
> Warning: preg_match_all() [function.preg-match-all]: Delimiter must
> not be alphanumeric or backslash


If you use the preg_* family, you have to use delimiters (any
non-alphanumeric character that's not the backslash) to surround your
pattern, so you can put modifiers behind the ending delimiter if you like.
'/' is the most commonly used.

preg_match_all('/D[0-9]{2}:[0-9]{2}:[0-9]{2}:[0-9]{2}/',$string,$matches);
--
Rik Wasmus
Reply With Quote
  #6 (permalink)  
Old 03-09-2008
Tim Roberts
 
Posts: n/a
Default Re: REGEX question

Feijó <afeijo@gmail.com> wrote:
>
>Him Tim, Thanks!
>
>Thats wierd, your code works on my pspad regex search (if found a
>example I type in my source-code), but when I run over php, this error
>is returned:
>
>Warning: preg_match_all() [function.preg-match-all]: Delimiter must
>not be alphanumeric or backslash
>
>You know why?


Rik posted the answer to this, but I'd like to take this opportunity to put
in a recommendation for an excellent and somewhat underappreciated book:
Jeffrey Friedl's "Mastering Regular Expressions".

I got the book originally on a whim, thinking "what could he possibly have
to say about regular expressions that would take a whole book", but I find
that I have referred to it again and again. It is an excellent and
thorough treatise on the subject. The third edition even includes a
45-page chapter on PHP.

And as a bonus, he includes a regular expression that matches every legal
RFC 822 email address. It is several tens of thousands of characters long.
--
Tim Roberts, timr@probo.com
Providenza & Boekelheide, Inc.
Reply With Quote
  #7 (permalink)  
Old 03-09-2008
John Dunlop
 
Posts: n/a
Default Re: REGEX question

Tim Roberts:

> And as a bonus, he includes a regular expression that matches every legal
> RFC 822 email address. It is several tens of thousands of characters long.


....much to your consternation if you don't have OCR!!

--
Jock
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are Off
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT +1. The time now is 10:49 PM.


Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO 3.0.0