Saturday, November 14, 2015

Java Regex match any character including newlines

Here's a short regex which is able to match any character including newlines in Java:


(\r|\n|.)+
For example, to remove all CPP comments, you can use something like this:
String str=str.replaceAll("/\\*(\r|\n|.)+\\*/", "");

No comments:

Post a Comment

Ubuntu 12.04, 14.04, 16.04 - auto start an app or script before login

To run a command or application at startup, even before the user has logged in, you can use this file: /etc/rc.local The commands entered...