Yang
Yang

Reputation: 1323

How could I match the three words

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

Answers (3)

braden.groom
braden.groom

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

Casimir et Hippolyte
Casimir et Hippolyte

Reputation: 89567

You can use a character class with . and _ , then you make it optional:

/m[._]?john/

for this particular example

Upvotes: 1

Tim Pietzcker
Tim Pietzcker

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

Related Questions