in reply to Regexp explanation

Your regexp would accept any combination of letters (would be A-Za-z in ASCII, but it depends on your locale), underline, and single quote. If you want it to allow words in quotes, and possibly surrounded by quotes, you could change it to
/('?[\w-]+'?)/g

Replies are listed 'Best First'.
Re: Re: Regexp explanation
by Anonymous Monk on Apr 02, 2004 at 20:17 UTC
    I want my string to accept composed word which have a character "-" between them such as "tear-down" or by-the-house; I don't need to be surrounded by quotes... maybe to get everything separate by blanks in a sentence?
      So then why did you put the quotes in your regex?

      Never mind. It is important to remember that the Perl regexps are greedy: they will match as much as possible. Therefore to match a word, you only need to specify what a word is, there is no need to define what it's delimiters might be.

      That simplifies the regexp to:

      /([\w-]+)/g