Beefy Boxes and Bandwidth Generously Provided by pair Networks
"be consistent"
 
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.

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?
[LanX]: did you even go to the Dutch Perl Workshop in Utrecht?
[erix]: haha ok. I'm going to Glasgow though, and make a long road trip round the isles
[erix]: [Lanx} not the last time but the one before (there have been two)
[LanX]: when did you move to Utrecht, you used to live in a windmill on a dyke walking around in wooden shoes. ..
[LanX]: ... did you lie to me? OO
erix wouldn't mind a nice old windmill to live in... Mueller/Miller/ Molenaar

How do I use this? | Other CB clients
Other Users?
Others meditating upon the Monastery: (11)
As of 2017-12-15 16:46 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    What programming language do you hate the most?




















    Results (439 votes). Check out past polls.

    Notices?