So, I have barely any clue how to operate regular expressions except for a little bit of knowledge of it in PHP.
What I'm trying to do is to separate the first part of a string from a qualifier, so I need a regular expression since I would ideally like to be able . The problem I'm having is that my attempt at the separation isn't working. I've tried doing what I think the Pattern or Matcher class does, I've tried using String.split, and I've tried using the regular String.replace method. What I'm trying to do is illustrated (I hope) in the following SSCCE:
public class SSCCE
{
public static void main(final String args[])
{
final String testString = "I want to keep this sentence. (I wish to "+
"discard this sentence and the space in between the sentences.)";
final String testExtract = testString.replace(" \(.+\)","");
System.out.println(testExtract);
}
}
From my understanding, parentheses are supposed to be a wild card of sorts, so they would need to be escaped in order to be taken as literals, which means that line 7 is supposed to match any of the characters inside the parentheses when the opening one is preceeded by a space and then delete them. The problem I'm having is that escaping the parentheses produces an error, and not escaping them produces the original string. So I'm not sure how to tell Java that I'm actually using literal parentheses.
I already tried configuring my error preferences to ignore everything it could, but that didn't work.
I don't know if it matters, but I'm using Java 1.6 and Eclipse for PHP 1.3.2.20110218-0812.