Skip to Main Content

Java Programming

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Regex for string in an XML element

807605Sep 11 2007 — edited Sep 11 2007
Hi all,

I'm creating a simple search-and-replace function for strings inside an XML document (specifically, I'm adding links to word-definitions within an educational program). However, I'd like the system to ignore anything that is within an pair of angled-brackets ("<>"). For example, in the text below,
<text>
  Blah blah blah <img src="blah blah"/> blah blah
</text>
I would want to IGNORE the "<text>" tags and the <img src="blah blah"/> element.

What's the best way to do this?

I thought I could just tell it to look for any string {string}, and not any string with an open bracket to the left and a close bracket to the right <.*{string}.*>, but this would ignore even the text I want, because it doesn't check if the brackets have been closed.

Any ideas would be much, much appreciated!
Sam
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Oct 9 2007
Added on Sep 11 2007
9 comments
756 views