Common Mistakes
Common Mistakes
===> egrep ' *H|help(less|ing)* ' fortunes
He sells C-Shells by the C-Shore.
Helping others ==> we all benefit.
No one can feel as helpless as the owner of a sick goldfish.
===> egrep ' *(H|h)elp(less|ing)* ' fortunes
Helping others ==> we all benefit.
No one can feel as helpless as the owner of a sick goldfish.
===> egrep ' *[Hh]elp(less|ing)* ' fortunes
Helping others ==> we all benefit.
No one can feel as helpless as the owner of a sick goldfish.
Notes:
Developing algorithms can include written explanations of what pattern you’re attempting to match.
Coding involves writing the pattern match which adheres to the pseudo language known as regular expressions
Debugging ensures that there are no logic flaws with the pattern matching code used. For example, is: “H|help” the same as “[H|h]elp”
In example One, we’re trying to match the words: Help, help, helpless, Helpless, helping, or Helping. Notice the mistake made in the regular expression specified. The expression for the first example is:
- Match a space zero or more times (which allows us to match the desired words in the beginning of the line.
- Then match a capital H or the word help.
- Then match the subexpression less or ing can occur zero or more times.
- Finally match a space
The expression is improved by changing the algorithm to:
- Match a space zero or more times.
- Then match a capital H or lowercase h as divided in the first parentheses grouping..
- Then match the string elp.
- Then match the subexpression less or ing (that involves the respective logical ORing in parentheses) where the expression can occur zero or more times.
- Finally match a space.
The third example is a better approach by performing a single character match specified in square braces. However, this is still not the best approach. A better expression would be: ________________