3
votes

I need to find all the words that have the specific characters(letters, numbers and special characters) and ignore the rest.

Here's my expression:

/[cwh]\w+/ig

Example:

  • Match: watch, because c, w aswell as h is present in that word

  • Skip: Welcome, because only c and W is present

The expression need match case insensitive.

Thank you very much for your help.

2
Wouldn't "Welcome" still match because it has a lowercase "c"? - musicnothing
I have edited your post to make your point clear to fellow users. If I've misunderstood your goal, rollback it. - kind user
@Kinduser Thanks, that's helpful. I can't tell if it's supposed to contain all of the letters or just some. - musicnothing
@musicnothing case-insensitive - Jefferson Reis

2 Answers

4
votes

You have to use positive lookaheads:

\b(?=\w*c)(?=\w*h)(?=\w*w)\w+

Live demo

0
votes

I'm not sure exactly what your match rules are - since both watch (lowercase w) and Welcome (lowercase c) would match the characters in your list. But

\w*[cwh]\w*/g

is probably what you're after.

This will match zero or more word characters, one character from your list, and zero or more word characters in a case sensitive fashion (w is distinct from W) globally (multiple matches possible per line).