Reputation: 211
I have these tags in my textarea
<gras>.....</gras>
And I'm trying to replace them using the replaceAll() String method
text.replaceAll("<gras>", "<b>");
text.replaceAll("</gras>", "</b>");
But, this regex code doesn't work. Any help please ?
Upvotes: 0
Views: 168
Reputation: 4713
You forgot a very important concept;
.
Change text.replaceAll("<gras>", "Bold!");
To
text = text.replaceAll("<gras>", "Bold!");
Assign text = some Function
, as text.replace() is creating a new String object and not referencing it.
Hope this helps.
Upvotes: 5
Reputation: 70939
Strings don't replace. Strings construct new Strings with the replacement values.
Also, if you are dealing with XML, regex is the wrong tool. That doesn't mean it can't work, and it might be useful in some limited examples, but it shouldn't be the first tool to use. Much like a hammer shouldn't be the first tool to use when installing a screw.
Upvotes: 2