1

I'm working on an expression that finds comments which begin with % and end with \n or \r and also multiple line comments /* */. I'm running into trouble for the one beginning with %. I can get it to detect when the comment starts but it is not terminating with a new line.

"(%.*\\n\\r)|(/\\*(?:.|[\\n\\r])*?\\*/)"

For example, if I have

%hello

nothing nothing nothing

fi

It takes the nothing nothing nothing line as a comment but not the fi line. I'm so confused.

1
  • 2
    This isn't a direct answer, but this site is really helpful for playing with RegEx in real time: fileformat.info/tool/regex.htm Commented May 9, 2011 at 21:27

2 Answers 2

2

Try this:

((?:%.*?[\\n\\r])|(?:/\\*(?:.|[\\n\\r])*?\\*/))

See here: rubular

Or with Pattern.DOTALL

(?s)((?:%[^\\n\\r]*)|(?:/\\*.*?\\*/))
Sign up to request clarification or add additional context in comments.

1 Comment

Your welcome. Btw. if an answer is solving your problem you should accept it.
1

http://ostermiller.org/findcomment.html

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.