Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change
 
PerlMonks  

Re: Regexp: How to match in middle but not the ends?

by TedPride (Priest)
on Jul 30, 2006 at 17:56 UTC ( #564643=note: print w/ replies, xml ) Need Help??


in reply to Regexp: How to match in middle but not the ends?

Perhaps the simplest solution is a two-part regex sequence:

$_ = '---LL--C----LCSH-------CSHL-------LCSLH-------LCCHLSHCL----'; while (m/([A-Z]+)/g) { ($s = $1) =~ s/^L+|L+$//g; print "$s\n" if $s; }
EDIT: Oops, missed that.


Comment on Re: Regexp: How to match in middle but not the ends?
Download Code
Replies are listed 'Best First'.
Re^2: Regexp: How to match in middle but not the ends?
by ikegami (Pope) on Jul 30, 2006 at 18:41 UTC

    It incorectly matches "C" in "-C-". (Two chars minimum.)

    $_ = '---LL--C----LCSH-------CSHL-------LCSLH-------LCCHLSHCL----'; while (m/([A-Z]+)/g) { ($s = $1) =~ s/^L+|L+$//g; print "$s\n" if length $s >= 2; }

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others having an uproarious good time at the Monastery: (10)
As of 2015-07-31 06:45 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (274 votes), past polls