On Feb 14, 12:40 pm, "kjh21" <heal... verizon.net> wrote:
> I have a requirement (using Java's regex framework)
that can be
> characterized generally as needing to match everything
between the
> (first) occurrence of two specified delimeter strings.
>
> More specifically, I'm trying to determine the value of
an attribute
> on the root tag of an XML document and would like to do
so without
> having to parse the corresponding document. So for
instance, given
> the input string
>
> <?xml version="1.0"?>
> <message type="messageA">
> ......
> </message>
>
> I would like for my regex to return the value
>
> messageA
>
> The regex I'm using currently
>
> static Pattern messageTypePattern =
Pattern.compile("type="[^"rn]*
> "");
>
> returns in the case of the example above
>
> type="messageA"
>
> Can the regex be refined to match only the characters
between my
> specified delimeters?
>
why not just use backreference? something like the
following:
static Pattern messageTypePattern =
Pattern.compile('type="([^"rn]*)"');
Matcher m = messageTypePattern.matcher(input_data);
if (m.find()) {
String messageType = m.group(1);
}
Dont know if the syntax is correct for Java, I don't know
Java
anyway.
Regards,
Xicheng
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the
Google Groups "Regex" group.
To post to this group, send email to regex googlegroups.com
To unsubscribe from this group, send email to
regex-unsubscribe googlegroups.com
For more options, visit this group at http://groups.go
ogle.com/group/regex
-~----------~----~----~----~------~----~------~--~---
|