-
Notifications
You must be signed in to change notification settings - Fork 1
quantifiers
Bruce Armstrong edited this page Oct 26, 2016
·
6 revisions
| Quantifier | Meaning |
|---|---|
| * | Match 0 or more times |
| + | Match 1 or more times |
| ? | Match 1 or 0 times |
| {n} | Match exactly n times |
| {n,} | Match at least n times |
| {n,m} | Match at least n but not more than m times |
The * and + are considered greedy because they match all they can before allowing the next part of the pattern to attempt matching. You can add a ? to turn off this behavior and match as little as possible. Ex: /\w+?/ or /\w*?/
- Match a floating point number (with some extra restrictions)
- Can start with a -
- Has 0 or more digits (
0|1|2|3|4|5|6|7|8|9can be replace with\d) - An optional . (Make sure you escape
\.it, or it will match one of your digits by mistake) - More digits. You probably want to force at least one here in case no period ever shows.
- Match whole numbers >= 1000
- Match whole numbers where 1000 <= n < 10,000
- Match whole numbers where 1000 <= n < 1,000,000
- Find the number substrings that start and end with 8. Ex: 885832834848 would find 88, 8328, 848, but not the whole string
12
843720
3813
1.234
-4.5
-4
-.5
-0
38.
82983271993
NaN
-4.4827e-2
8437284773984342448937247292837493729347882738
885832834848