Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical
 
PerlMonks  

Re: split on the pattern of '),('

by kennethk (Monsignor)
on Jun 07, 2012 at 19:47 UTC ( #975026=note: print w/ replies, xml ) Need Help??


in reply to split on the pattern of '),('

If you need to escape characters in a regular expression, you can reliably use either the quotemeta function or the delimiters \Q and \E, as described in Quote and Quote like Operators. For example, you would successfully split with my @arr = split /\Q),(\E/, $str;.

On examining your input, it's possible you'll get more mileage from either a state machine character-wise parser, a regular expression, or my favorite in this context, multiple operations including a different basic split. Since you appear to be separating tuples, you could use my @arr = split /(?<=\))\s*,\s*(?=\()/, $str; to separate the tuples, and then deal with each one individually.

#11929 First ask yourself `How would I do this without a computer?' Then have the computer do it the same way.


Comment on Re: split on the pattern of '),('
Select or Download Code

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others imbibing at the Monastery: (11)
As of 2014-10-23 13:50 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    For retirement, I am banking on:










    Results (125 votes), past polls