RegEx: capture all the phrases with hyphen in them

42 Views Asked by At

I have a very long list of words that after converting from another format, some of the words in it are hyphenated. for example:

book, im-moral, law
intesti-nal, lung
flimflam*, fly-by-night*, illegal,

How can I capture all the phrases that have hyphen in them? In case of above example it would be:

im-moral
intesti-nal
fly-by-night

RegEx flavor: regular expressions engine implemented in EditPad Pro 7

1

There are 1 best solutions below

0
Rajeshwar On BEST ANSWER

Please take a look at this plunker link. As anubhava mentioned, we can use the same regexp. I have also added a simple example to check it.

`

var str = 'book, im-moral,law,intesti-nal,lung, flimflam*, fly-by-night*, illegal';

var re = /([a-zA-Z]+(-[a-zA-Z]+)+)/gi;
var found = str.match(re);
alert(found)

`