Beefy Boxes and Bandwidth Generously Provided by pair Networks
Pathologically Eclectic Rubbish Lister
 
PerlMonks  

Re: Regular expression for a comma separated string

by Anonymous Monk
on Nov 23, 2014 at 23:43 UTC ( [id://1108197]=note: print w/replies, xml ) Need Help??


in reply to Regular expression for a comma separated string

"Without repetition" sounds difficult. Why does it have to be a single monstrous regular expression? Is it just for fun?
  • Comment on Re: Regular expression for a comma separated string

Replies are listed 'Best First'.
Re^2: Regular expression for a comma separated string
by naderra (Novice) on Nov 24, 2014 at 00:10 UTC
    It doesn't have to be. I didn't mention earlier, I did try to break it down but with no success.
    /^(?=[ACGT]{1,4},[ACGT]{1,4}$).*$/ && /^(?!.*(.).*\1.*,).*$/ && /^(?!,.*(.).*\1).*$/
      Well then, I'd do it like that
      my @lst = qw( A,G AG,CT TC,CA GAT,CGA CGAT,TG ,G ACGT X,A AA,G AC,GGC ATGA,TGG ATCXG,AAC ATA,TG GTA,YC); for (@lst) { my $good = do { m/^ [ATCG]+ , [ATCG]+ $/x and not grep m/(.) .* \1/x, split ','; }; print $_, $good ? ' good' : ' bad', "\n"; }
      Output:
      A,G good AG,CT good TC,CA good GAT,CGA good CGAT,TG good ,G bad ACGT bad X,A bad AA,G bad AC,GGC bad ATGA,TGG bad ATCXG,AAC bad ATA,TG bad GTA,YC bad

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others about the Monastery: (5)
As of 2024-04-18 07:42 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found