Solved

Perl regex - skip first match or beginning

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

How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

Join & Write a Comment

I have been pestered over the years to produce and distribute regular data extracts, and often the request have explicitly requested the data be emailed as an Excel attachement; specifically Excel, as it appears: CSV files confuse (no Red or Green h…
Checking the Alert Log in AWS RDS Oracle can be a pain through their user interface.  I made a script to download the Alert Log, look for errors, and email me the trace files.  In this article I'll describe what I did and share my script.
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…

759 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

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now