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("(...
|
|||||||
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
|
|||
|
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? |
|
|||
|
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 |
|
|||
|
> > 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? |
|
|||
|
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" = @. |
|
|||
|
> >>>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"? |