--- In perl-beginner%40yahoogroups.com">perl-beginner
yahoogroups.com, "hooyar66" <pcbcad
...> wrote:
>
> I have been struggling with a Regex and would appreciate some help.
>
> The regex needs to convert to underscores all the whitespace that
is
> found between two quotation marks, so my test code should produce:
>
> ---
> $line was LED_5P05_2X10_2Y60_SMT "LED_SMT-YELLOW DIFFUSED
> REPLACE,1.90MMA" D1
> $line now LED_5P05_2X10_2Y60_SMT "LED_SMT-
> YELLOW_DIFFUSED_REPLACE,1.90MMA" D1
> ---
>
> I have made many unsuccessful attempts at a regex but am having a
> problem coding the correct pattern between the quote characters. I
> include what I believe is the closest to the correct code but
produces
>
> ---
> $line was LED_5P05_2X10_2Y60_SMT "LED_SMT-YELLOW DIFFUSED
> REPLACE,1.90MMA" D1
> $line now LED_5P05_2X10_2Y60_SMT "D REPLACE,1.90MMA_D" D1
> ---
>
> Thanks for all and any help
> NJH
>
>
> #!c:/perl/bin/perl.exe -w
>
> use strict;
> use diagnostics;
>
> my $line = 'LED_5P05_2X10_2Y60_SMT "LED_SMT-YELLOW DIFFUSED
> REPLACE,1.90MMA" D1';
>
> print "$line was $linen";
>
> $line =~ s/"((S+)s+(S+))+"/"$1_$2"/g;
>
> print "$line now $linen";
>
> #----------------
> #END
>
The code below is a solution - but is there a neater way?
#!c:/perl/bin/perl.exe -w
use strict;
use diagnostics;
my $line = 'LED_5P05_2X10_2Y60_SMT "LED_SMT-YELLOW DIFFUSED
REPLACE,1.90MMA" D1';
print "$line was: $line";
$line =~ /"(.+)"/;
my $str = $1;
my $str2 = $str;
$str2 =~ s/s/_/g;
$line =~ s/$str/$str2/;
print "$line now: $linen";
.