Search code examples
regexeditpad

RegEx: capture all the phrases with hyphen in them


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


Solution

  • 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)
    

    `