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