Hi,
How to replace symbol "%" with a word "Percent".
My original string is "Internal (%) External (%)". The string should be "Internal (Percent) External (Percent)"
Using regular expression, how I can replace this symbol?
Thanks in advance. Atul
Hi,
How to replace symbol "%" with a word "Percent".
My original string is "Internal (%) External (%)". The string should be "Internal (Percent) External (Percent)"
Using regular expression, how I can replace this symbol?
Thanks in advance. Atul
You don't need a Regex here, you can use a regular replace. For example using .net:
string s = "Internal (%) External (%)";
s = s.Replace("%", "Percent");
Hi, the match string will simply be a percent symbol: %
However, implementing is specific to your regex environment.
Javascript
var myString = "Internal (%) External (%)";
myString = myString.replace(/%/g,"Percent");
What language are you using? In many languages, you wouldn't need a regex for this, e.g., in Python...:
>>> "Internal (%) External (%)".replace('%','Percent')
'Internal (Percent) External (Percent)'
but if you did want to use RE for some peculiar reason, that would also be easy:
>>> import re
>>> re.sub('%', 'Percent', "Internal (%) External (%)")
'Internal (Percent) External (Percent)'
the details of performing such a global replacement, with REs or without them, will vary by language, so it's hard to offer specific help without knowing what language you're using!-)
How can i replace the ^ sybol.I have tried str.replace(/^/g."Cap");But its is not working.Please provide a better solution for this.
Thanks in advance...