Fero45
asked on
Perl regex - skip first match or beginning
Hi experts
I have a pipe delimited file:
ORIANA|LIGHT BLUE GOLD/SILVER LIGHT GREEN|0|0|1|0|0|0||0|0|0|0 | ...
PERLA|WHITE|0|0|0|0|0|0|0| 0| ...
1391002|Bronze|0|7|2|1|0|0 |0|0|0|0|0 |0|
PG88|Bronze|0|7|2|1|0|0|0| 0|0|0|0|0|
Some lines begin with a capitalized string, some with a number, some with a combination of numbers and letters, as seen above.
I want to keep the first match capitalized and have all subsequent word matches (colors) with only the first letter capitalized.
I have a pipe delimited file:
ORIANA|LIGHT BLUE GOLD/SILVER LIGHT GREEN|0|0|1|0|0|0||0|0|0|0
PERLA|WHITE|0|0|0|0|0|0|0|
1391002|Bronze|0|7|2|1|0|0
PG88|Bronze|0|7|2|1|0|0|0|
Some lines begin with a capitalized string, some with a number, some with a combination of numbers and letters, as seen above.
I want to keep the first match capitalized and have all subsequent word matches (colors) with only the first letter capitalized.
When I have e.g.
my $str ="ORIANA|LIGHT BLUE GOLD/SILVER LIGHT GREE|0|0|1|0|0|0|0|0|0";
$str =~ s#\b(\w+)\b#\L\u$1\E#gx;
it gives me almost satisfactory:
"Oriana|Light Blue Gold/Silver Llight Green|0|0|1|0|0|0|0|0|0";
.. except the first match which I want to remain ORIANA.
Fero
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
my $str ="ORIANA|LIGHT BLUE GOLD/SILVER LIGHT GREE|0|0|1|0|0|0|0|0|0";
$str =~ s#(?<=\W)(\w+)#\L\u$1#g;
$str =~ s#(?<=\W)(\w+)#\L\u$1#g;
ASKER