Painless regex not match when string have a "\n"

I have my regex like this:

def m = /(.+)webservice.*/.matcher(x);if ( m.matches()) {return;

The problem is it just match when my string have no "\n" like :

"mbccs_getStatusIncorrectProfile webservice does not exist"

and fail:

"mbccs_getStatusIncorrectProfile webservice does not exist\n"

How can I catch in second case? And even with other characters like "\r" ...Thanks.

Hi @le_ba_nam

The \ character is a special char in Regex so you need to escape it.
Can you try the following

String escape(def x) { /([\\])/.matcher(x).replaceAll('\\') };
def m = /(.+)webservice.*/.matcher(escape(x));
if ( m.matches()) {return;

And let me know if it worked?

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.