How to escape a square bracker (regex)
1 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   Bozhidar_Bozhanov
Posted On:   Sunday, November 5, 2006 04:23 PM

I need to "tell" my java code to replace the sequence "[a-z]" as it is.
I.e.
String a = "[a-z]";
a = a.replaceAll("[a-z]", "other");

So I need to escape the "[" and "]". But writing "]" triggers an error. Is there a workaround?

Re: How to escape a square bracker (regex)

Posted By:   WarnerJan_Veldhuis  
Posted On:   Monday, November 6, 2006 05:21 AM

You need to escape the [ in RegEx, so you would get [, but in a String [ is invalid, so you need to escape the escape :). So it would become \[
About | Sitemap | Contact