Skip to Main Content

New to Java

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 & Multiline pattern between 2 tags (a better way).

843785Oct 2 2008 — edited Oct 20 2008
Hi there,

I've a String which contains 2 known tags and a bunch of data on a multilines in-between (those data and number of lines are un-known (can be different everytime).

I'm using a regex to find the data and replace it. BUT would like to find a more elegant way of doing it.

Here is example of my String:
------------------------------------------
<actualCommand><?xml version='1.0' encoding='utf-8'?><soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"><soapenv:Header>
.....
xmlns:wsss+="</soapenv:Header><soapenv:Body>
<default:rpc xmlns=" message-id="742">
<default:edit-config> <target> </target> <config>
.....
.....
bla-bla-bla
.....
.....
</config></default:edit-config>
</default:rpc>
</soapenv:Envelope></actualCommand>
------------------------------------------

Here is my regex I'm using (and it works fine):
=====================
String regexActualCommand = "<actualCommand>[A-Za-z0-9 !@#$%^&\"?<>/:;\'=,.\n\r\t\\+-]*</actualCommand>";
=====================

Is there are more elegant for regex??? I tried this one - but it works if there is 1 line only in-between those tags: String regexActualCommand = "<actualCommand>.+</actualCommand>";
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Nov 17 2008
Added on Oct 2 2008
14 comments
1,383 views