Beefy Boxes and Bandwidth Generously Provided by pair Networks
Think about Loose Coupling
 
PerlMonks  

Re: Regexp. Combination of words block. Need help.

by Corion (Patriarch)
on Feb 09, 2020 at 10:47 UTC ( [id://11112672]=note: print w/replies, xml ) Need Help??


in reply to Regex. Combination of words block. Need help.

Why do you need to do this all in one regular expression?

Also, do you mean that the space in front of  ccc should be treated differently from the space between abc Qwerty?

Also, why does Qwerty not show up as a separate string in your other examples?

If you want a simple approach, just split the string on /[;,\s]+/ to get an array, and then get all the sub-sequences of that array:

#!perl use strict; use warnings; my $string = 'aaa, bbb, ccc,ddddd;eee-12345abc Qwerty'; my @items = split /[,;\s]+/, $string; for my $i (0..$#items) { for my $j ($i..$#items) { print join " - ", @items[ $i .. $j ]; print "\n"; }; } __END__ aaa aaa - bbb aaa - bbb - ccc aaa - bbb - ccc - ddddd aaa - bbb - ccc - ddddd - eee-12345abc aaa - bbb - ccc - ddddd - eee-12345abc - Qwerty bbb bbb - ccc bbb - ccc - ddddd bbb - ccc - ddddd - eee-12345abc bbb - ccc - ddddd - eee-12345abc - Qwerty ccc ccc - ddddd ccc - ddddd - eee-12345abc ccc - ddddd - eee-12345abc - Qwerty ddddd ddddd - eee-12345abc ddddd - eee-12345abc - Qwerty eee-12345abc eee-12345abc - Qwerty Qwerty

Log In?
Username:
Password:

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

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

    No recent polls found