w7r.blogspot.com
Let's Avoid Being Redundant!
Regular Expressions can save you a lot of time, by describing complicated patterns that would be ridiculous to search documents for with a standard Search and Replace.
Repeat Operators
| Symbol |
Quantity |
Example |
| + |
One or more |
| Regex |
Captures |
Ignores |
| "w+" |
"w", "wwwww", "wkd", "switch" |
"123", "mango", "smiley_faces", "" |
|
| * |
Zero or more |
| Regex | Captures | Ignores |
| "a*" |
"aab", "ab", "b", "LotsOfStuff", "" |
NO CASES |
|
| ? |
one or zero |
| Regex | Captures | Ignores |
| "2?" |
"2", "a", "2a", "a2" |
"22", "0122", "a22b" |
|
Practice Makes Perfect
Try and create the simplest regular expression to identify each text case below! Feel free to comment your answers. FYI: We are taking baby steps so if this is too easy (which it very well may be!) then feel free to skip this exercise.
- aaabbbbccccc
- knee
- cabbage
- 22nd street
Answers to these questions will be in Regex Tutorial #3.
No comments:
Post a Comment