variables in regex's

Discussion in 'Java' started by vivekhungund@gmail.com, Feb 6, 2007.

  1. Guest

    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.
    , Feb 6, 2007
    #1
    1. Advertising

  2. hiwa Guest

    On Feb 6, 10:23 am, 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");
    hiwa, Feb 6, 2007
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. =?Utf-8?B?SmViQnVzaGVsbA==?=

    Is ASP Validator Regex Engine Same As VS2003 Find Regex Engine?

    =?Utf-8?B?SmViQnVzaGVsbA==?=, Oct 22, 2005, in forum: ASP .Net
    Replies:
    2
    Views:
    688
    =?Utf-8?B?SmViQnVzaGVsbA==?=
    Oct 22, 2005
  2. Rick Venter

    perl regex to java regex

    Rick Venter, Oct 29, 2003, in forum: Java
    Replies:
    5
    Views:
    1,604
    Ant...
    Nov 6, 2003
  3. Replies:
    2
    Views:
    589
  4. Replies:
    9
    Views:
    924
  5. Replies:
    3
    Views:
    726
    Reedick, Andrew
    Jul 1, 2008
Loading...

Share This Page