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 biv343 on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

String Parsing Help Needed

Status
Not open for further replies.

billyb

Technical User
Nov 18, 2001
5
EU
Hi I wonder if you can help?

I want to replace the first two letters of a word with another. For example

America
would become

BBerica

I know this is a easy one but help great.


 
The following will work.

$string = s/^\w{2}/BB/;

The 's' is the substitution operator.
The syntax for this operator is:
s/match/replace/

So for the match we have:
The '^' is to match the beginning of the string.
The '\w{2}' is to match exactly 2 word characters.

This match is replaced with 'BB'.

Hope this helps.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top