Regular Expressions: Excluding specific characters

Problem:

Using regular expressions, match the words hog and dog with but not bog.

Output:







Solution:


The simplest solution to match any line that ends in 'og' but is not 'bog' would be the expression '[^b]og'. Alternatively, you could use what we learned from the previous lesson and use '[hd]og' to match 'hog' and 'dog' but not 'bog'. Note that is is slightly more restrictive expression because it limits the strings it can match. 


1 comment :

  1. Zedge App Download is a popular mod apk that allows users to customize their smartphones in a variety of ways. The app has a variety of features, including the ability to change the background, ringtone, and icons. There are also a number of themes available for zedge, as well as options to change the theme and font size.

    ReplyDelete

Follow Me

If you like our content, feel free to follow me to stay updated.

Subscribe

Enter your email address:

We hate spam as much as you do.

Upload Material

Got an exam, project, tutorial video, exercise, solutions, unsolved problem, question, solution manual? We are open to any coding material. Why not upload?

Upload

Copyright © 2012 - 2014 Java Problems  --  About  --  Attribution  --  Privacy Policy  --  Terms of Use  --  Contact