/    Sign up×
Community /Pin to ProfileBookmark

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

to post a comment
Java

1 Comments(s)

Copy linkTweet thisAlerts:
@ExuroJul 11.2005 — I'm pretty sure you can just do this with a "lazy star", which matches the smallest number of characters as it can:
&lt;SENTENCE&gt;.[color=red]*?[/color]&lt;/SENTENCE&gt;
You'll probably need to use the [url=http://java.sun.com/j2se/1.5.0/docs/api/java/util/regex/Pattern.html#MULTILINE]MULTILINE[/url] flag in your pattern.
×

Success!

Help @obaid1982 spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.19,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...