1

I need a regexp to get all string inside a tags like it: <- -> inside this tags include any character, numbers, spaces, carriage return etc. i have this regexp:

Pattern.compile("<-(.+?)->") 

but it not detect a special sequence as: \r \n etc.

0

3 Answers 3

2

but it not detect a special sequence as: \r \n etc

It won't match newline unless you use Pattern.DOTALL flag as in:

Pattern p = Pattern.compile("<-(.+?)->", Pattern.DOTALL);

OR else you can use (?s) flag:

Pattern p = Pattern.compile("(?s)<-(.+?)->");

Pattern.DOTALL makes dot match new line character so .+? will also match \r,\n etc.

Sign up to request clarification or add additional context in comments.

Comments

1

You can try the following:

<-([\\S\\s]+?)->

Comments

0

The . character does not match line breaks. This is why you are having the issue.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.