4
More Pattern Recognition With Regular Expressions

More Pattern Matching With RegEx

Embed Size (px)

Citation preview

More Pattern Recognition With

Regular Expressions

Alternatives

• The vertical bar, often referred to as, ”or” , means that only the left or right of the bar has to match.• Code: |

• Ex./agent007|agent(.)/g{1}7//Jason ( |\t)+Silverstein(\.|/g{1})/

Character Classes

• A character class is a list of possible characters that can be matched on.• Matches on a single character• Contained in brackets

• Code: [characters]• Ex. [abc] [abcxyz] [a-cx-z] [aegr-t] [a-zA-Z] [0-9]/agent00[1-9]/

Negation

• Sometimes it is easier to list the one case that it is not instead of all the possible cases that it is.

• Question: What is one of these cases?

• A caret in the front of the character class negates it or not in.• In other words will match on any character except the ones listed in the

list.• Code: [^characters]

• Ex. [^abc] [^A-Z]