Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Perl regex - skip first match or beginning

Posted on 2009-07-13
3
Medium Priority
?
372 Views
Last Modified: 2012-08-14
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

0
Comment
Question by:Fero45
3 Comments
 
LVL 39

Accepted Solution

by:
Adam314 earned 2000 total points
ID: 24842457

s#\b((?<=.)\w+)\b#\L\u$1\E#gx;

Open in new window

0
 
LVL 6

Author Closing Comment

by:Fero45
ID: 31602931
Thanks Adam. I will always be an apprentice only.
0
 
LVL 85

Expert Comment

by:ozo
ID: 24842909
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;
0

Featured Post

New feature and membership benefit!

New feature! Upgrade and increase expert visibility of your issues with Priority Questions.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

by Batuhan Cetin Regular expression is a language that we use to edit a string or retrieve sub-strings that meets specific rules from a text. A regular expression can be applied to a set of string variables. There are many RegEx engines for u…
Whatever be the reason, if you are working on web development side,  you will need day-today validation codes like email validation, date validation , IP address validation, phone validation on any of the edit page or say at the time of registration…
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
Six Sigma Control Plans

824 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question