|
|
multiline regex expression
This should have been an easy expression to build, but I can't figureit out.I just want to match any text between the <!--scripts--> and <!-endscripts--> tag:<!--scripts--> <script src="assets/scripts/tabber.js" type="text/javascript"></script> <script type="text/javascript" src="management.js"></script> <script type="text/javascript" src="assets/scripts/prototype.js"></script> <script src="assets/scripts/scriptaculous.js" type="text/javascript"></script> <script type="text/javascript" src="assets/scripts/MMSService.js"></script><!--endscripts-->
|
|
0
|
|
|
|
Reply
|
eggie5 (73)
|
7/21/2007 4:33:22 AM |
|
On Jul 21, 1:33 pm, eggie5 <egg...@gmail.com> wrote:> This should have been an easy expression to build, but I can't figure> it out.>> I just want to match any text between the <!--scripts--> and <!-> endscripts--> tag:>> <!--scripts-->> <script src="assets/scripts/tabber.js" type="text/javascript"></> script>>> <script type="text/javascript" src="management.js"></script>>> <script type="text/javascript" src="assets/scripts/prototype.js"></> script>>> <script src="assets/scripts/scriptaculous.js" type="text/> javascript"></script>>> <script type="text/javascript" src="assets/scripts/> MMSService.js"></script>>> <!--endscripts--> String text = "yumyum<!--scripts-->\n<script src=\"assets/scripts/tabber.js\" type=\"text/javascript\"></\nscript>\n<script type=\"text/javascript\" src=\"management.js\"></script>\n<script type=\"text/javascript\" src=\"assets/scripts/prototype.js\"></\nscript>\n<scriptsrc=\"assets/scripts/scriptaculous.js\" type=\"text/\njavascript\"></script>\n<script type=\"text/javascript\" src=\"assets/scripts/\nMMSService.js\"></script>\n<!--endscripts-->\nmommom"; String regex = "(?s).*<!--scripts-->(.*)<!--endscripts-->.*"; String result = text.replaceAll(regex, "$1"); System.out.println(result);
|
|
0
|
|
|
|
Reply
|
SadRed
|
7/21/2007 5:38:28 AM
|
|
On Sat, 21 Jul 2007 04:33:22 +0000, eggie5 wrote:> This should have been an easy expression to build, but I can't figure it> out.> > > > I just want to match any text between the <!--scripts--> and <!-> endscripts--> tag:Try using Pattern.compile("<!--scripts-->(.*)<!--endscripts-->", Pattern.DOTALL).matcher( /string/ ).group(1);(from Java API, Pattern documentation: ) The regular expression . matches any character except a line terminator unless the DOTALL flag is specified.
|
|
0
|
|
|
|
Reply
|
Joshua
|
7/21/2007 4:55:39 PM
|
|
On Jul 22, 1:55 am, Joshua Cranmer <Pidgeo...@verizon.net> wrote:> On Sat, 21 Jul 2007 04:33:22 +0000, eggie5 wrote:> > This should have been an easy expression to build, but I can't figure it> > out.>> > I just want to match any text between the <!--scripts--> and <!-> > endscripts--> tag:>> Try using Pattern.compile("<!--scripts-->(.*)<!--endscripts-->",> Pattern.DOTALL).matcher( /string/ ).group(1);>> (from Java API, Pattern documentation: )>> The regular expression . matches any character except a line terminator> unless the DOTALL flag is specified.Hey Josh, (?s) == DOTALL.Didn't you know that?
|
|
0
|
|
|
|
Reply
|
SadRed
|
7/21/2007 9:02:29 PM
|
|
On Sat, 21 Jul 2007 14:02:29 -0700, SadRed <cardinal_ring@yahoo.co.jp>
wrote, quoted or indirectly quoted someone who said :
>Hey Josh, (?s) == DOTALL.
see http://mindprod.com/jgloss/regex.html#FLAGS
--
Roedy Green Canadian Mind Products
The Java Glossary
http://mindprod.com
|
|
0
|
|
|
|
Reply
|
Roedy
|
7/22/2007 2:09:01 AM
|
|
|
4 Replies
230 Views
(page loaded in 0.066 seconds)
|
|
|
|
|
|
|
|
|