Jump to content


Photo

Regex & Newline Break... cry for help!


  • Please log in to reply
2 replies to this topic

#1 gregchet

gregchet
  • New Members
  • Pip
  • Newbie
  • 4 posts

Posted 17 July 2006 - 02:23 AM

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
----------

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

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

#2 gregchet

gregchet
  • New Members
  • Pip
  • Newbie
  • 4 posts

Posted 17 July 2006 - 03:57 AM

You can ignore this post.

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

#3 effigy

effigy
  • Staff Alumni
  • Advanced Member
  • 3,600 posts
  • LocationIL

Posted 17 July 2006 - 04:32 AM

/\*{5} Hand History for Game (\d+) \*{5}\s+25/i

\n works fine, unless you need an \r\n.
Regexp | Unicode Article | Letter Database
/\A(e)?((1)?ff(?:(?:ig)?y)?|f(?:ig)?)\z/




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users