Extraction of attribute values from pattern matches

Discussion in 'Java' started by Peekachu, Jul 8, 2006.

  1. Peekachu

    Peekachu Guest

    Hi,

    My program has to deal with a lot of text of the pattern:

    "Name=userLocale", "Value=English", ENDITEM

    I need to do two things:
    1> Check if the text matches a certain pattern.
    2> If there is a pattern match, extract the attribute value parts
    ('userLocale' and 'English', in the text above) of the text into
    Strings or a String array.

    The first part is easy to do using the Pattern and Matcher classes. I
    am struggling with the second part. It is easy to do it using the
    String class methods such as 'split' and 'substring' but I was looking
    for a more elegant way to do this, since I need to do this operation in
    several places throughout my program.

    Thanks,
    Peekachu
     
    Peekachu, Jul 8, 2006
    #1
    1. Advertising

  2. Peekachu

    Oliver Wong Guest

    "Peekachu" <> wrote in message
    news:...
    > Hi,
    >
    > My program has to deal with a lot of text of the pattern:
    >
    > "Name=userLocale", "Value=English", ENDITEM
    >
    > I need to do two things:
    > 1> Check if the text matches a certain pattern.
    > 2> If there is a pattern match, extract the attribute value parts
    > ('userLocale' and 'English', in the text above) of the text into
    > Strings or a String array.
    >
    > The first part is easy to do using the Pattern and Matcher classes. I
    > am struggling with the second part. It is easy to do it using the
    > String class methods such as 'split' and 'substring' but I was looking
    > for a more elegant way to do this, since I need to do this operation in
    > several places throughout my program.


    Write a parser with transforms your strings into model objects
    representing the information. For inspiration, see XML parsers and DOM.

    - Oliver
     
    Oliver Wong, Jul 10, 2006
    #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. Ram Laxman
    Replies:
    1
    Views:
    425
    Brad Baxter
    Jul 15, 2004
  2. aekalman
    Replies:
    6
    Views:
    135
    Ben Morrow
    Nov 22, 2004
  3. doni

    Pattern Matching and Extraction

    doni, Jan 22, 2007, in forum: Perl Misc
    Replies:
    10
    Views:
    181
    John Bokma
    Jan 23, 2007
  4. Deepan - M.Sc(SE) - 03MW06

    Perl pattern extraction

    Deepan - M.Sc(SE) - 03MW06, Mar 8, 2008, in forum: Perl Misc
    Replies:
    4
    Views:
    103
    Tad J McClellan
    Mar 9, 2008
  5. Deepan - M.Sc(SE) - 03MW06

    Perl pattern matching and extraction

    Deepan - M.Sc(SE) - 03MW06, Mar 8, 2008, in forum: Perl Misc
    Replies:
    1
    Views:
    114
    Gunnar Hjalmarsson
    Mar 8, 2008
Loading...

Share This Page