Jump to content

Archived

This topic is now archived and is closed to further replies.

gregchet

Regex & Newline Break... cry for help!

Recommended Posts

I'm trying to do what I thought would be a simple regex replacement, but no matter what I try it doesn't seem to want to work.

I'm trying to do a regex search for the below text (which is part of the $string variable):

----------
***** Hand History for Game 1111111111 *****
25 NL
----------

[code]
$pattern = "/\*\*\*\*\* Hand History for Game ([0-9]*) \*\*\*\*\*\\n25/i";
$replacement = "test";
preg_replace($pattern, $replacement, $string)
[/code]

1) As soon as I move the "25" up a line so that it's right after the last * on the previous line, and then remove the "\\n" from the regex search it works fine, which is how I know it's a newline issue.

2) As suggested by other information I've found online (including php.net), I've tried "\\n", "\\\n", and "\\\\n" in the regex search, but none of them work.

Does anyone have any suggestions before I pull the rest of my hair out? :P

Share this post


Link to post
Share on other sites
You can ignore this post.

I'm going to go a completely different route with the way the matches are being done.

Share this post


Link to post
Share on other sites
/\*{5} Hand History for Game (\d+) \*{5}\s+25/i

\n works fine, unless you need an \r\n.

Share this post


Link to post
Share on other sites

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.