Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?
 
PerlMonks  

Re: Regex with newline

by voyager (Friar)
on Apr 04, 2001 at 23:25 UTC ( [id://69823]=note: print w/replies, xml ) Need Help??


in reply to Regex with newline

Update: Thanks for the help. It was the return character. This works:
$text =~ s|\r\n\r\n|<br /><br />|sg;

Replies are listed 'Best First'.
Re: Re: Regex with newline
by dvergin (Monsignor) on Apr 05, 2001 at 03:21 UTC
    Note that thabenksta's example does not include the '/s'. You do not need it and you obscure its meaning and usefulness when you use it reflexively just because you are working with multiple lines.

    '/s' simply allows '.' to match line break characters. It has no other effect on the ability of your regex to work with multiple lines.

Re^2: Regex with newline
by typomaniac (Novice) on Feb 07, 2012 at 02:50 UTC
    I know this was an old post but it answered a question for me however it also brought up another one....is there any way to limit the number of
    tags to only two..that is, no matter how many times a user presses the enter key paragraphs are separated by two spaces(and no more than two). Thanks
      Yes. For example:
      $text =~ s%(?:\r\n){2,}%<br /><br />%g;

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://69823]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others having an uproarious good time at the Monastery: (6)
As of 2024-04-19 10:04 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found