www.webdeveloper.com
Results 1 to 2 of 2

Thread: help with Regular Expression

  1. #1
    Join Date
    Jul 2005
    Posts
    2

    help with Regular Expression

    I am trying to extract a string from xml file using regex. Here is a sample of xml file:

    <SENTENCE>
    <TEXT>today is monday</TEXT>
    <BIT>4</BIT>
    <...> blah blah blah </...>
    </SENTENCE>

    Now i want to grab everything between <SENTENCE> and </SENTENCE> including the 'text' and 'bit' tags. My approach is to use negation:

    String abs = "<SENTENCE>(^(</SENTENCE)*)</SENTENCE>";


    but it doesnt quite work. I know how to negate single characters, but how do i negate an entire a string? Thanks in advance

  2. #2
    Join Date
    Dec 2002
    Location
    Taiwan
    Posts
    1,297
    I'm pretty sure you can just do this with a "lazy star", which matches the smallest number of characters as it can:
    Code:
    <SENTENCE>.*?</SENTENCE>
    You'll probably need to use the MULTILINE flag in your pattern.
    The Web Standards Project Build accessible standard compliant websites, please!
    Browse Happy Don't forget to support the browsers with standard compliance

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles