Pcre regular expression to ignore newlines
I've a PCRE regular expression of the following form:
Foo:\\s*(.*)
When this is used to match Foo: b开发者_开发百科ar\n then the group match contains the newline also. How can I change the regular expression to remove the newline from the group match.
If you can turn off .
matches \n
then do that.
Otherwise, place an optional newline at the end.
Foo:\\s*(.*)\n?
Or you could swap (.*)
with (\S*)
Foo:[^\\S\\r\\n]*(.*)
This will match whitespace but not Carriage Return (\r) or New Line (\n). If you find that .*
is matching newlines too you can change the expression to:
Foo:[^\\S\\r\\n]*([^\\r\\n]*)
精彩评论