rp.kelly
rp.kelly

Reputation: 28

Java Regex to find instances of "[" in a string

I'm currently working on a UIMA based project, and the data set I am using has some predefined plain-text annotations that I am trying to convert into UIMA annotations using the Matcher utility.

My problem is that the annotations are in the format [ANNO] [/ANNO], and I have no idea how to write '[' or ']' as a regular expression.

I tried searching various places, and couldn't find an answer to this, closest I could find is to use either the octal or hexidecimal value rendition, but I then can't actually find said rendition for the character.

Cheers

Upvotes: 0

Views: 144

Answers (1)

user130076
user130076

Reputation:

As Dervall said, you must escape them:

Pattern pattern = pattern.compile("\\[");
Matcher matcher = pattern.matcher("string to match against");

Upvotes: 4

Related Questions