Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

simple regex issue

Status
Not open for further replies.

eggbaconsandwich

Programmer
Mar 5, 2015
1
GB
Hi tek-tips.

Perl noob here, I have the following code for turning anything to lower case after 3 slashes :

Perl:
$input = 'tea/coffee/eggs/BACON'; 
$output = $input =~ s/^((?:.*?\/){3}(.*)$/$1.lc($2)/er;
print $output;

Question, how can I quickly reverse the application of lc and only apply it to $1 instead of $2? I.e. turn anything to lower case up until finding 3 slashes, once 3 slashes found do not alter the rest.

Thanks in advance.
 
Hi

I generally agree with Franco, but in this case I would use a regular expression :
Perl:
[navy]$input[/navy] [teal]=[/teal] [i][green]'Tea/Coffee/Eggs/Bacon'[/green][/i][teal];[/teal]
[navy]$output[/navy] [teal]=[/teal] [navy]$input[/navy] [teal]=~[/teal] [b]s[/b][fuchsia]!^((?:[^/]*/){3})!\L$1![/fuchsia]r[teal];[/teal]
[b]print[/b] [navy]$output[/navy][teal];[/teal]


Feherke.
feherke.ga
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top