Solved

Perl regex - skip first match or beginning

Posted on 2009-07-13
3
355 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 500 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 84

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

ScreenConnect 6.0 Free Trial

Discover new time-saving features in one game-changing release, ScreenConnect 6.0, based on partner feedback. New features include a redesigned UI, app configurations and chat acknowledgement to improve customer engagement!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Regex-What is a great online tool for regex? 12 50
Need some Regex Help 3 48
Specific format 21 198
asp.net c# execute .bat server side problem 6 70
On Microsoft Windows, if  when you click or type the name of a .pl file, you get an error "is not recognized as an internal or external command, operable program or batch file", then this means you do not have the .pl file extension associated with …
A year or so back I was asked to have a play with MongoDB; within half an hour I had downloaded (http://www.mongodb.org/downloads),  installed and started the daemon, and had a console window open. After an hour or two of playing at the command …
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…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…

777 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