Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery
 
PerlMonks  

Re: Re: TIMTOWTDI

by tachyon (Chancellor)
on Sep 11, 2003 at 02:29 UTC ( [id://290582]=note: print w/replies, xml ) Need Help??


in reply to Re: TIMTOWTDI
in thread LCCS time complexity

Hi, looking at your REs I have a couple of suggestions:

$text =~ s/\[.*?\]/ /g; # you can lose the .*? by using [^\]]* which save the RE engine ba +cktracking # $text =~ s/\[[^\]]*\]/ /g; $text =~ s/[.,?"':&()!-]/ /g; $text =~ s/[^\w ]//g; # you need a /m to make this match # here # and here # and here # ie this will only match the very begining of the string $text =~ s/^\s+//; # ditto $text =~ s/\s+$//; $text =~ s/\s+/ /;

cheers

tachyon

s&&rsenoyhcatreve&&&s&n.+t&"$'$`$\"$\&"&ee&&y&srve&&d&&print

Replies are listed 'Best First'.
Re: Re: Re: TIMTOWTDI
by rkg (Hermit) on Sep 11, 2003 at 10:38 UTC
    Thanks for the   $text =~ s/\[[^\]]*\]/ /g; tip; that is better. As for the  /m on these
    $text =~ s/^\s+//; $text =~ s/\s+$//;
    I think I'd put the  /m on the third RE
    $text =~ s/\s+/ /m; #yes?
    so taken together the triple REs mean: "remove leading whitespace, trailing whitespace, and make all interior whitespace (even across line breaks) into single spaces".

    Many thanks for the OT-but-useful teaching!

    rkg

      The /m only modifies the match behaviour of ^ and $ letting them match the begining and end of any line rather than entire string. It has no effect on the final RE which just needs a /g to do all interior whitespace.

      cheers

      tachyon

      s&&rsenoyhcatreve&&&s&n.+t&"$'$`$\"$\&"&ee&&y&srve&&d&&print

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others meditating upon the Monastery: (4)
As of 2024-03-28 22:34 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found