Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change
 
PerlMonks  

Re: Regular expression

by Samy_rio (Vicar)
on Aug 27, 2007 at 09:33 UTC ( [id://635256]=note: print w/replies, xml ) Need Help??


in reply to Regular expression

Hi Archana, try like this,

use strict; use warnings; my $str ='"Transcription factor" promoter DNA "Transcription factor" p +romoter DNA.'; my @str = split//, $str; my $fla = 1; for (@str){ if (($_ eq "\"") && $fla) { $fla = 0; }elsif (($_ eq "\"") && !($fla)){ $fla = 1; } $_ =~ s/ /\,/ if ($fla); } print join'',@str; __END__ Output: ------- "Transcription factor",promoter,DNA,"Transcription factor",promoter,DN +A.

TIMTOWTDI, we can achieve the expected output using RegExp as of below:

$str =~ s/((?:(?!\").)*)(\"[^\"]+\")((?:(?!\").)*)/ my $fi = $1;my $se = $2; my $th = $3; $fi =~ s| |\,|g;$th =~ s| |\,|g; "$fi$se$th"/egs;

Regards,
Velusamy R.


eval"print uc\"\\c$_\""for split'','j)@,/6%@0%2,`e@3!-9v2)/@|6%,53!-9@2~j';

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others having a coffee break in the Monastery: (3)
As of 2024-04-25 19:51 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found