By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,948 Members | 795 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,948 IT Pros & Developers. It's quick & easy.

simple egrep - regex question

P: n/a
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?
Jul 17 '05 #1
Share this Question
Share on Google+
6 Replies


P: n/a
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

Jul 17 '05 #2

P: n/a
> > 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?
Jul 17 '05 #3

P: n/a
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, <de*****@cauce.org> is een "spam trap".
E-mail adres is <jpk"at"akamail.com>, waarbij "at" = @.
Jul 17 '05 #4

P: n/a
> >>>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"?
Jul 17 '05 #5

P: n/a
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

Jul 17 '05 #6

P: n/a
> > 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!
Jul 17 '05 #7

This discussion thread is closed

Replies have been disabled for this discussion.