Reputation: 1323
If a word like 'm.john', or 'm_john', or 'mjohn', how could I match all of them?
I tried /\w+/, but obviously, the '.' won't be matched
Thanks.
Upvotes: 1
Views: 51
Reputation: 325
If you want to match letters, digits, underscores and periods then you can use this:
/[\w.]+/
If you dont want to include digits then use this:
/[a-zA-Z._]+/
If you dont want to match capital letters then leave that part out:
/[a-z._]+/
Upvotes: 1
Reputation: 89567
You can use a character class with .
and _
, then you make it optional:
/m[._]?john/
for this particular example
Upvotes: 1
Reputation: 336208
You can add more characters to the set of allowed characters by using a character class:
/[\w.]+/
The _
is already matched by \w
.
Upvotes: 1