RE: [PHP] preg_match question
| From: | Nicklas Bondesson | Date: | Wed, 18 Aug 2004 16:18:19 +0000 |
| Subject: | RE: [PHP] preg_match question | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-194163@lists.php.net to get a copy of this message | ||
Actually I think I got it working now (without escaping the ".").
If I run into trouble I will post again.
Thanks!
Nicke
________________________________
From: John Legg [mailto:john@modupe.co.uk]
Sent: den 18 augusti 2004 18:15
To: "Nicklas Bondesson"
Cc: php-general@lists.php.net
Subject: RE: [PHP] preg_match question
Hi Nicke
Difficult to say without knowing exactly what you are trying to achieve. If
you are just comparing two strings for 'exactness' then it would probably be
better to just do a direct string comparison (without regex). Regex's are
generally more expensive operations.
One thing you should do is escape the "." portion of the URL you are
comparing. As "." matches any character except newline. So it should be:
$pattern = "/^www\.test\.com$/";
If you tell me what you are trying to achieve, I might be able to advise
further.
Rgds
John
---
Is it clever to use word boundary here? "/b"?
Nicke
________________________________
From: John Legg [mailto:john@modupe.co.uk
<http://uk.f251.mail.yahoo.com/ym/Compose?To=john@modupe.co.uk&YY=19751&orde
r=down&sort=date&pos=0&view=a&head=b> ]
Sent: den 18 augusti 2004 18:02
To: "Nicklas Bondesson"
Cc: php-general@lists.php.net
<http://uk.f251.mail.yahoo.com/ym/Compose?To=php-general@lists.php.net&YY=19
751&order=down&sort=date&pos=0&view=a&head=b>
Subject: Re: [PHP] preg_match question
Try using a pattern set to the following:
$pattern = "/^www.test.com$/";
and refer to:
http://uk.php.net/manual/en/reference.pcre.pattern.syntax.php
Rgds
John
---
Hello,
How do I find an exact match of a string with preg_match?
Example:
String1: www.test.com/
String2: www.test.com/somepage.php?param1=true
How do you write the regexp to only return String1 and not String2 when
you
match against "www.test.com" ??
Thanks in advance.
Nicke
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php