Velocity Reviews

Velocity Reviews (http://www.velocityreviews.com/forums/index.php)
-   Java (http://www.velocityreviews.com/forums/f30-java.html)
-   -   variables in regex's (http://www.velocityreviews.com/forums/t390642-variables-in-regexs.html)

vivekhungund@gmail.com 02-06-2007 01:23 AM

variables in regex's
 
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.


hiwa 02-06-2007 05:41 AM

Re: variables in regex's
 
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");



All times are GMT. The time now is 08:21 AM.

Powered by vBulletin®. Copyright ©2000 - 2014, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.