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

Re: Complex Splitting

by tcf03 (Deacon)
on Feb 06, 2007 at 14:03 UTC ( #598542=note: print w/replies, xml ) Need Help??


in reply to Complex Splitting

This should do the trick - Its only tested on your string though...
#!/usr/bin/perl use strict; use warnings; my $string = "ABC[GHI]XYZ"; my @array; splitstring($string); push @array, split//, $string; print "$_ " for sort @array; sub splitstring { return unless ( $string =~ /.*\[\w+\].*/ ); if ( $string =~ /.*(\[(\w+)\]).*/ ) { my $remove = $1; my $str = $2; print "rem = $remove\n str = $str\n"; push @array, $str; $string =~ s/\Q$remove\E//; } splitstring($string); }
UPDATE
I substututed the string with [987]ABC[GHI]XYZ[dfg] and that works as well.

regards

Ted
--
"That which we persist in doing becomes easier, not that the task itself has become easier, but that our ability to perform it has improved."
  --Ralph Waldo Emerson

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (4)
As of 2022-05-25 17:47 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Do you prefer to work remotely?



    Results (90 votes). Check out past polls.

    Notices?