Regex question

Any questions involving matching text strings to patterns - the pattern is called a "regular expression."

Moderator: General Moderators

Post Reply
HiddenS3crets
Forum Contributor
Posts: 119
Joined: Fri Apr 22, 2005 12:23 pm
Location: USA

Regex question

Post by HiddenS3crets »

Question using preg_match()

This is my current line:

Code: Select all

preg_match("/<([a-z])?\>(.*?)\<\/([a-z])?\>/", $str, $matches);
How can I have preg_match() return true if I have multiple lines submitted

Example:

Code: Select all

<php><? echo "hello world"; ?></php>
That submission will work, but if I do:

Code: Select all

<php><?
echo "hello world";
?></php>
it does not work. Any idea on how I can make it accept line breaks?
User avatar
Oren
DevNet Resident
Posts: 1640
Joined: Fri Apr 07, 2006 5:13 am
Location: Israel

Post by Oren »

Assuming that this code works: (didn't read it)

Code: Select all

preg_match("/<([a-z])?\>(.*?)\<\/([a-z])?\>/", $str, $matches);
All you've got to do is to add the 's' modifier like this:

Code: Select all

preg_match("/<([a-z])?\>(.*?)\<\/([a-z])?\>/s", $str, $matches);
timvw
DevNet Master
Posts: 4897
Joined: Mon Jan 19, 2004 11:11 pm
Location: Leuven, Belgium

Post by timvw »

Post Reply