Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw
 
PerlMonks  

Re: Regex Question

by cat2014 (Monk)
on Jan 08, 2001 at 00:03 UTC ( [id://50376]=note: print w/replies, xml ) Need Help??


in reply to Regex Question

i think that you want something like:

$text =~ s/([^\n])\n{1}([^\n])/$1$2/g;

this should match exactly 1 newline which is surrounded by a non-newline character on either side. the {1} modifies the character before it & tells it that you have to match exactly 1. it's a pretty good thing to learn- basically, you do:
m/x{1,}/ if you want to match at least 1
m/x{1,5}/ if you want to match at least 1 and most 5, etc.

you should read the perlre page for more information.

update:

the above code, as merlyn pointed out, is wrong- you should use his example. but i still think that you should read the perlre page. (:

Replies are listed 'Best First'.
Re: Re: Regex Question
by merlyn (Sage) on Jan 08, 2001 at 00:08 UTC

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others exploiting the Monastery: (6)
As of 2024-04-25 11:04 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found