laredotornado <> wrote in news:50016a00-9422-46d4-
8278-:
> On May 31, 12:28*pm, Andreas Leitgeb <a...@gamma.logic.tuwien.ac.at>
> wrote:
>> laredotornado <laredotorn...@zipmail.com> wrote:
>> > Hi,
>> > I'm using Java 1.6. *How would I modify my regular expression below
>> > ^Starting at \$32,000*$
>>
>> ^Starting at \$32,000\*$
>>
>> > so that it will match the string, "Starting at $32,000*". *In other
>> > words, I have
>> > String regEx = "^Starting at \\$32,000*$";
>>
>> String regEx = "^Starting at \\$32,000\\*$";
>>
>> > String text = "Starting at $32,000*";
>> > if (!text.matches(regEx)) {
>> > * * * throw new RuntimeException("does not match");
>> > }
>> > but the exception is always thrown. *Please let me know how can I
>> > modify my reg ex to match. *Thanks, - Dave
>>
>>
>
> Is there a way I can match an arbitrary string without having to
> escape everything? I tried putting my token in quotes ...
>
> String regEx = "^Starting at (\"$32,000*\")$";
>
> but that failed to match. - Dave
Have you looked at Pattern.quote(String s) in java.util.regex.Pattern ? It
may be what you want. Here is an example:
import java.util.regex.Pattern;
public class PatternQuote {
public static void main(String[] args) {
String orig = "Starting at $32,000*" ;
String quoted = "^" + Pattern.quote(orig) + "$" ;
System.out.println(orig + " became " + quoted) ;
}
}