• Post Reply Bookmark Topic Watch Topic
  • New Topic

Help with java reg expression please  RSS feed

 
nick moore
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi All! Is it possible to write a regular expression that will only return true if the pattern does not begin with 3 exclamation points (!!!).

I have tried:

[^(!!!)]
[^!!!]
[^!{3}]
etc...

any ideas?
 
Alan Moore
Ranch Hand
Posts: 262
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
No, really, that's how you do it. The (?!<regex>) construct is a negative lookahead: it says "If <regex> would match at this point, fail". What you were doing, [^<set>], is a negated character class: it says "match any one character as long as it isn't a member of <set>". So with [^(!!!)] you're matching any character that's not a parenthesis or an exclamation point (most characters lose their special meanings within a character class).

There's a good regex tutorial at http://www.regular-expressions.info/
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!