Wikia

WoWWiki

Talk:USERAPI GetWords

100,556pages on
this wiki

Back to page | Redirected from Talk:GetWords

I had a look at GetWords today, and BC seems to have introduced a few things which can improve GetWords. I've always struggled with regex, so I was a pretty happy when this worked...

function YourAddOn:GetWords(str)
  local retVal = {};
  for nxtW in string.gmatch( msg, "(%p*%w*%p*%w+)%s*" ) do
    table.insert( retVal, nxtW );
  end
  return( retVal );
end

That regex/pattern keeps integral punctuation with a word, as well as leading punctuation. So...

  • we've
  • sub-sub==section
  • $3.50
  • _under-score
  • #->a

... would remain intact, but input such as...

  • yes...
  • pre-male,
  • Hey!!
  • ?Who?

...would have the trailing punctuation removed.

But yeah, regex isn't one of my string points, so maybe someone could come up with a cleaner way to acheive that part. It's seems a bit too convoluted.

Kord 13:21, 4 March 2007 (EST)

Around Wikia's network

Random Wiki