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-->
SadRed - 21 Jul 2007 06:38 GMT
> This should have been an easy expression to build, but I can't figure
> it out.
[quoted text clipped - 18 lines]
>
> <!--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<script
src=\"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);
Joshua Cranmer - 21 Jul 2007 17:55 GMT
> 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.
SadRed - 21 Jul 2007 22:02 GMT
> > This should have been an easy expression to build, but I can't figure it
> > out.
[quoted text clipped - 9 lines]
> 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?
Roedy Green - 22 Jul 2007 03:09 GMT
>Hey Josh, (?s) == DOTALL.
see http://mindprod.com/jgloss/regex.html#FLAGS

Signature
Roedy Green Canadian Mind Products
The Java Glossary
http://mindprod.com