Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Regular Expressions  RSS feed

 
Jeff Storey
Ranch Hand
Posts: 118
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm trying to use regular expessions to strip out multi-line html comments. The following is an example of what I'm trying to do:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1DTD/xhtml1-transitional.dtd">

The way I'm trying to match this is:
Pattern comments = Pattern.compile("<!.*?|[\n]*?>", Pattern.MULTILINE);

But this only gets the opening <! and the end > as two separate groups. I haven't had luck returning the whole pattern as a single group (so I can easily delete it). Can someone explain to me how to fix this?

Thank you,
Jeff
 
Henry Wong
author
Sheriff
Posts: 23283
125
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
try...

Pattern comments = Pattern.compile("<!.*?>", Pattern.DOTALL);


Henry
 
Jeff Storey
Ranch Hand
Posts: 118
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Henry - that did the trick.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!