Regex question plus Pattern.COMMENTS;
Posted: Fri Jul 12, 2013 9:27 am
Hi,
I would like to know why the following happens:
Pattern.COMMENTS ignores white spaces and comments starting with #.
The comment gets ignored, however the whitespace between the slashes are not.
I believe it because the compiler sees it as a wrong escape sequence.
However if I try to escape the slash as:
Then the space between \\ and \1 does not get ignored and thus does not provide me with the same result as if there were no spaces and no "Pattern.COMMENTS.
Is there any way to avail of the Pattern.COMMENTS and the white spaces in the above mentioned context?
Thanks in advance.
The_Nick.
I would like to know why the following happens:
Code: Select all
Pattern pt = Pattern.compile(" ( a ) \ \1#commentscomments",Pattern.COMMENTS);
The comment gets ignored, however the whitespace between the slashes are not.
I believe it because the compiler sees it as a wrong escape sequence.
However if I try to escape the slash as:
Code: Select all
Pattern pt = Pattern.compile(" ( a ) \\ \1#commentscomments",Pattern.COMMENTS);
Is there any way to avail of the Pattern.COMMENTS and the white spaces in the above mentioned context?
Thanks in advance.
The_Nick.