Reputation: 4420
i have regular expression which need to cover multi lines(delete comments from pascal file)
\(\*.*?\*\)|\{.*?\}|\/\/(.*$)
this works almost fine but
\(\*.*?\*\)
and
\{.*?\}
are supposed to work for multilines, but work for single only. How to make them working right(and dont make
//(.*$)
work for multi lines)
Thanks in advance
Upvotes: 0
Views: 89
Reputation: 26940
This will match literally everything, including newlines:
Pattern regex = Pattern.compile("[\\s\\S]*");
Upvotes: 1
Reputation: 33928
You are looking for the Pattern.DOTALL
flag. Pass it to Pattern.compile
like so:
Pattern p = Pattern.compile("regex", Pattern.DOTALL);
You can also set it in the regex with (?s)
, like: "(?s)regex"
Upvotes: 1