Q1: | What's the difference between m// and just //? |
A1: | Nothing, really. The m is optional, unless you're using a different character for the pattern delimiter. They both do the same thing. |
Q2: | Alternation produces a logical OR situation in the pattern. How do I do a logical AND? |
A2: | The easiest way is simply to use multiple patterns and the && or and operators, like this:
/pat1/ && /pat2/; If you know the order in which the two patterns will appear, you can just do something like this: /pat1.*pat2/ |
Q3: | I have a pattern that searches for numbers: /d*/. It matches for numbers, all right, but it also matches for all other strings. What am I doing wrong? |
A3: | You're using * when you mean +. Remember that * means “zero or more instances.” That means if your string has no numbers whatsoever, it'll still match—you've got zero instances. + is used for at least one instance. |