This week's book giveaway is in the Design forum.
We're giving away four copies of Design for the Mind and have Victor S. Yocco on-line!
See this thread for details.
Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Regex - Difference in ^[abc] and [^abc]

 
O. Ziggy
Ranch Hand
Posts: 430
Android Debian VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am trying to find out what is the difference between ^[abc] and [^abc]

I tried two simple examples using



Output






:Output


I know that the first one is saying get any character that is not a, b or c

- When you say [^abc], shouldnt abc have been in brackets for the ^ character apply to all three characters?
- Please explain the difference in output of the above two examples.
 
Darryl Burke
Bartender
Posts: 5125
11
Java Netbeans IDE Opera
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
^ outside a character class isn't a negation, it's the start of input.

Recommended reading:
http://download.oracle.com/javase/tutorial/essential/regex/index.html
http://www.regular-expressions.info/
 
O. Ziggy
Ranch Hand
Posts: 430
Android Debian VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
oh ok that makes sense.
 
O. Ziggy
Ranch Hand
Posts: 430
Android Debian VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Darryl Burke wrote:^ outside a character class isn't a negation, it's the start of input.

Recommended reading:
http://download.oracle.com/javase/tutorial/essential/regex/index.html
http://www.regular-expressions.info/


Thanks for this. That second one is quite good..
 
Bert Bates
author
Sheriff
Posts: 8898
5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
off the top of my head, I think this topic is outside the scope of the exam... it would be worth double checking

to be sure, the exam focuses on a small subset of regex
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic