On Feb 6, 10:23 am, vivekhung...@gmail.com wrote:
> Hi, I was wondering how to incorporate a string variable into a
> regex. So I've got an array of rules "S -> NP VP" "NP -> dog" etc.,
> and a sentence "the dog is blue". I want to match each word in the
> sentence to the corresponding rule in my array.
> Say the rule "NP -> dog" is myArray[1]. I want something like:
> Pattern pattern = Pattern.compile("\bmyArray[1]\b")
>
> I'd appreciate any advice.
>
> Thanks.
Pattern pattern = Pattern.compile("\\b" + myArray[1] + "\\b");
|