I have a string by "This is apples, it costs me &xyz and I bought them at &abc"
I need to get the folowing output
"This is apples, it costs me {xyz} and I bought them at {abc}"
Basically I need to replace &word with {word}
Thanks
Sri
|
Newbie Member
|
|
| 9Feb2008,06:56 | #2 |
|
Words beginning with & needs to be replaced with {} around them. Please help
|
|
Go4Expert Member
|
|
| 9Feb2008,13:01 | #3 |
|
Code:
$string =~ s!&(\S+)!{$1}!g; ## $string contains the string
|
|
Go4Expert Member
|
|
| 25Feb2010,15:04 | #4 |
|
Dear friend,
You can use the following way also. Code:
$var="This is apples, it costs me &xyz and I bought them at &abc";
$var=~s!&([a-z]{3})!{$1}!g;
print "$var\n";
|
|
Light Poster
|
|
| 26Feb2010,13:59 | #5 |
|
You can also use the following script.
$str=~s/&(\w+)/{$1}/g print $str |
|
Go4Expert Member
|
|
| 2Mar2010,10:49 | #6 |
|
See the following code. It will match & followed by n number of
numbers/characters. Code:
$val =~ s/&(.*) /{$1}/g;
print $val;
|
|
Go4Expert Member
|
|
| 9Mar2010,12:22 | #7 |
|
Quote:
Originally Posted by ungalnanban Code:
$val =~ s/&(.*)/{$1}/g;
print $val;
sorry, I think while copy and pasting time the space is added. |
|
Newbie Member
|
|
| 25Jun2010,21:06 | #8 |
|
hi friend,
pls try to do it. its working well. $str =~ s/&(\w+)/{$1}/gs; |

