Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I want to match the following string using regular expressions in Java:

suspicious url test' xts#dfd

I don't want the regex to match if there is a quote, (') This is what I'm using.

suspicious url\s.*(?!')

When i use this I match the whole string.

share|improve this question

closed as off-topic by slhck Jul 23 '13 at 14:13

  • This question does not appear to be about computer software or computer hardware within the scope defined in the help center.
If this question can be reworded to fit the rules in the help center, please edit the question.

This depends completely on what kind of regex you are using. Are these POSIX? EREGex? Perl? Sed? what? – terdon Jun 13 '13 at 13:11
@terdon uses java regex to match it. – asadz Jun 13 '13 at 13:12
This question appears to be off-topic because it is about Java programming. – slhck Jul 23 '13 at 14:13
up vote 3 down vote accepted

The problem is that the .* will match everything before the look ahead even happens. If you just want to make sure that a ' does not follow until the end of the line try:

suspicious url\s[^']*$
share|improve this answer

Not the answer you're looking for? Browse other questions tagged .