Can't get the right regexp

  • 14 years ago
    Hi

    I'm trying to remove excess newline characters from a string passed from a file_get_contents. I'm using preg_replace with /\n{2,}+/s to be replaced with "". I tried it with a string that I set, "a\n\n\n\n\nb" that returned the result that I wanted ("a\nb"). But the one from file_get_contents doesn't get replaced. I checked with addcslashes if it had other characters like \r, but it didn't seem to have them.

    My suspect is my regular expression.

    Thanks!







Post a reply

No one has replied yet! Why not be the first?

Sign in or Join us (it's free).

Contribute

Why not write for us? Or you could submit an event or a user group in your area. Alternatively just tell us what you think!

Our tools

We've got automatic conversion tools to convert C# to VB.NET, VB.NET to C#. Also you can compress javascript and compress css and generate sql connection strings.

“Measuring programming progress by lines of code is like measuring aircraft building progress by weight.” - Bill Gates