Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Java > variables in regex's

Reply
Thread Tools

variables in regex's

 
 
vivekhungund@gmail.com
Guest
Posts: n/a
 
      02-06-2007
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.

 
Reply With Quote
 
 
 
 
hiwa
Guest
Posts: n/a
 
      02-06-2007
On Feb 6, 10:23 am, (E-Mail Removed) 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");

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
what is difference between Class variables and Instance variables? rahul8143@gmail.com Java 10 06-06-2011 06:43 AM
Put variables into member variables or function variables? tjumail@gmail.com C++ 9 03-23-2008 04:03 PM
Session Variables and Static Variables cobus.lombard@gmail.com ASP .Net 1 03-26-2006 11:05 AM
Accessing class member variables - properties or variables? dwok Java 7 03-04-2005 03:54 AM
Re: Class public shared Variables vs. Application Variables in ASP.NET avnrao ASP .Net 0 05-07-2004 05:28 AM



Advertisments