Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much
 
PerlMonks  

Re: REGEX detailed character replace

by marcussen (Pilgrim)
on Nov 12, 2008 at 05:27 UTC ( #723057=note: print w/ replies, xml ) Need Help??


in reply to REGEX detailed character replace

s/|(xx)-(xxx)-(xxxxx)-(xxx x/xx)|(xx)-(xxxx)-(xxx)-(xx)-(xxxx)-(xx)-(xx)|/\1-\2-\3-\4,\5,\6etc;

Confucius says kill mosquito unless cannon


Comment on Re: REGEX detailed character replace
Download Code
Re^2: REGEX detailed character replace
by ww (Bishop) on Nov 12, 2008 at 14:45 UTC
    Well, though this is rather distant from a general solution, it does answer the OP's stated question so no downvote even though the regex is scarcely more than an identity.

    It could be generalized a bit:

    $string =~ s/\|(\S+)\s([^-|]+)[-|](x+)[-|](x+)[-|](x+)[-|](x+)[-|](x+)[-|](x+)[-|](x+).*/$1,$2,$3,$4,$5,$6,$7,$8,$9,/;

    But that's still far from general, relying on "x" rather than [A-Za-z0-9]+ -- which I suspect comes closer (but still clumsily) to OP's "real" question." See, for example, ikegami's reply.

    Update: Linkified to clarify my "this"

      Granted, I should probably have been more helpful, for instance Anonymous Monk does this, but I have a tendency to get lazy/sloppy/careless when giving out fish.

      Confucius says kill mosquito unless cannon

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others pondering the Monastery: (7)
As of 2015-07-03 15:59 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 (53 votes), past polls