Jump to content

Regex & Newline Break... cry for help!


gregchet

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
Link to comment
https://forums.phpfreaks.com/topic/14807-regex-newline-break-cry-for-help/
Share on other sites

Archived

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

×
×
  • Create New...

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.