simple egrep - regex question

This is a discussion on simple egrep - regex question within the PHP Language forums, part of the PHP Programming Forums category; To match "this" or "that" in string $str, I believe I would use this: eregi("(...


Go Back   Usenet Forums > PHP Programming Forums > PHP Language

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 12-15-2004
deko
 
Posts: n/a
Default simple egrep - regex question

To match "this" or "that" in string $str, I believe I would use this:

eregi("(this|that)", $str)

but what if I want to match "this" AND "that"?

I suppose I could use this:

eregi("this", $str) && eregi("that", $str)

But is there a better way?


Reply With Quote
  #2 (permalink)  
Old 12-15-2004
Janwillem Borleffs
 
Posts: n/a
Default Re: simple egrep - regex question

deko wrote:
> To match "this" or "that" in string $str, I believe I would use this:
>
> eregi("(this|that)", $str)
>
> but what if I want to match "this" AND "that"?
>
> I suppose I could use this:
>
> eregi("this", $str) && eregi("that", $str)
>
> But is there a better way?


eregi("this.*that|that.*this", $str)


JW



Reply With Quote
  #3 (permalink)  
Old 12-15-2004
deko
 
Posts: n/a
Default Re: simple egrep - regex question

> > eregi("this", $str) && eregi("that", $str)
> >
> > But is there a better way?

>
> eregi("this.*that|that.*this", $str)


Is this saying: match the four letters "this" followed by a period, then
any combinbation of characters, then the four letters "that" (and vice
versa). What does the period do?


Reply With Quote
  #4 (permalink)  
Old 12-15-2004
Jan Pieter Kunst
 
Posts: n/a
Default Re: simple egrep - regex question

deko wrote:
>>>eregi("this", $str) && eregi("that", $str)
>>>
>>>But is there a better way?

>>
>>eregi("this.*that|that.*this", $str)

>
>
> Is this saying: match the four letters "this" followed by a period, then
> any combinbation of characters, then the four letters "that" (and vice
> versa). What does the period do?
>
>


The period stands for 'any character'. So .* stands for: zero or more of
any character.

JP

--
Sorry, <devnull@cauce.org> is een "spam trap".
E-mail adres is <jpk"at"akamail.com>, waarbij "at" = @.
Reply With Quote
  #5 (permalink)  
Old 12-15-2004
deko
 
Posts: n/a
Default Re: simple egrep - regex question

> >>>eregi("this", $str) && eregi("that", $str)
> >>>
> >>>But is there a better way?
> >>
> >>eregi("this.*that|that.*this", $str)

> >
> >
> > Is this saying: match the four letters "this" followed by a period,

then
> > any combinbation of characters, then the four letters "that" (and vice
> > versa). What does the period do?
> >
> >

>
> The period stands for 'any character'. So .* stands for: zero or more of
> any character.


I see. So, "this.*that" can be loosely understood to mean "match this and
that"?


Reply With Quote
  #6 (permalink)  
Old 12-15-2004
Janwillem Borleffs
 
Posts: n/a
Default Re: simple egrep - regex question

deko wrote:
> I see. So, "this.*that" can be loosely understood to mean "match
> this and that"?


Yep: this anything-in-between-and that


JW



Reply With Quote
  #7 (permalink)  
Old 12-15-2004
deko
 
Posts: n/a
Default Re: simple egrep - regex question

> > I see. So, "this.*that" can be loosely understood to mean "match
> > this and that"?

>
> Yep: this anything-in-between-and that


10-4. Thanks for the help!


Reply With Quote
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
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

BB 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 09:40 AM.


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