I have a set of words in an array and i would like to get only the ones that match the regexp i apply to.
Let’s say I have the following set of words:
friend
fired
fried
afternoon
affiliate
activate
staff
neafe
and i need to apply a regexp that accomplish the following rules:
1.- One regexp that get only words that starts with ‘f’.
2.- One regexp that get only words that ends with ‘f’.
3.- One regexp that get only words that contains ‘f’.
4.- One regexp that get only words that has one letter before ‘f’.
5.- One regexp that get only words that has one letter after ‘f’.
so, results for every case would be:
case 1
friend
fired
fried
case 2
staff
case 3
friend
fired
fried
afternoon
affiliate
staff
neafe
case 4
afternoon
affiliate
case 5
staff
neafe
Need help please.
They will all match only if the word fits the criteria you described for each case:
^f.*.*f$f^.ff.$of course the input of each pattern MUST be a single word