Regex: Matching Set
Regular Expression Sets:
You may not want to match every character, but a large number of specific characters. RegEx gives you the ability to match any character in a given set by using the special bracket characters
- match any lowercase letter
- match any uppercase letter
- match any single digit
- match a comma, period, or semicolon
- match any case letter and the numbers 1-5
You can build whatever set fits your specific needs.
Match any two digit number starting with
grep '3[0-9]' user.csv
Match the numbers
grep '3[5-9]' user.csv
Match the beginning of the line, then exactly
Paul, and then any uppercase letter between
grep '^Paul,[A-F]' user.csv
RegEx sets give you fine tuned control over what can and cannot be matched.
You can also define an exclusion set in RegEx.
Match the beginning of the line, then any character not in
grep '^[^AEIOU]' user.csv
The exclusion group symbol is a set with the
^ character. Making it very similar to the begin line anchor