Regexp expression issue

N

nicolaspujol

Hi,

GOAL: return in the content of the appropriate xforms:instance node
identified by its id:

I have the following pattern but it is incorrect.

(<xforms:instance.*id=\"services\")(.*)(</xforms:instance>)

It seems to work well up until the (.*) group. For some reason the
parser does not stop at the first occurence of </xforms:instance>
Any thoughts?

=====THE STRING===
<xforms:instance xmlns="" id="nicolas">
<root>
<choice></choice>
</root>
</xforms:instance>
<xforms:instance xmlns="" id="services">
<webservices>
<ws id="1">Zip Code Weather</ws>
<ws id="2">Distance between 2 points</ws>
</webservices>
</xforms:instance>

=====THE CODE=====
strMatch_pattern="
(<xforms:instance.*id=\"services\")(.*)(</xforms:instance>)";
pattern=Pattern.compile(strMatch_pattern,Pattern.DOTALL);
matcher=pattern.matcher(new StringBuffer(p_strForm));
sb=new StringBuffer();
while(matcher.find())
{
System.out.println(matcher.group(1));
System.out.println(matcher.group(2));
System.out.println(matcher.group(3));

}
matcher.appendTail(sb);
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads

java.util.Regexp.Matcher issue with double quote 1
regexp 10
Question on regular expression. 6
complex regex 1
complex regex 1
Some regexp problems 7
Java regexp help 2
Optimizing HTML links parser 10

Members online

No members online now.

Forum statistics

Threads
473,780
Messages
2,569,611
Members
45,280
Latest member
BGBBrock56

Latest Threads

Top