Link to home
Start Free TrialLog in
Avatar of Fero45
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.
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

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of Adam314
Adam314

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Fero45
Fero45

ASKER

Thanks Adam. I will always be an apprentice only.
Avatar of ozo
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;