Solved

Perl regex - skip first match or beginning

Posted on 2009-07-13
3
363 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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

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 …
There are many situations when we need to display the data in sorted order. For example: Student details by name or by rank or by total marks etc. If you are working on data driven based projects then you will use sorting techniques very frequently.…
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…

828 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