'undefined' matches in AS3 RegExp? huh?

I've got a long regex in AS3 / Flex which finds one of a couple dozen words. The Regex looks like: word|wordup|wordly|wordster

when I do "wordup wordster!".match(regex) I'm getting undefined maches! the match array that's returned has matches: [0] 'wordup' [1] undefined array length: 2

Is there a known bug in AS3's grouping matches? What could make some words show up in the returned array of matches, and others return as undefind?

I've looked for stray incorrect characters in my regular expression, and inspected the regular expression several times over.

If I just search for 'wordup' then I get a match array length 1, with the correct contents. If I search for just 'wordster' then I get an array length one with matches[0] being undefined again.

------ update -------

After lots of experimenting... my regular expression was just too long for AS3 My actual regular expression used grouping, and had optional parenthesis:

(?:(?(\bword\b))?|(?(\bwordup\b))?| ... and so on for 51 words.

simplifying to: (?:\bword\b|\bwordup\b|

somehow made the match groups work just fine, even though I don't have any parenthesis that would normally be necessary to define groups...

Answers


When you're dealing with "mystery" problems, you should always show your actual code, not something you think is equivalent. word|wordup|wordly|wordster won't give you any "undefined" matches.

Instead of using (?:\bword\b|\bword2\b), use this: \b(?:word|word2)\b

The regex word|(word2)?|word3 will give you zero-length matches, because the second alternative in the regex is optional. It will match the zero-length string at every position in the string where "word" cannot be matched.


Need Your Help

Jbuilder: How to encode an array of hashes?

json elasticsearch jbuilder

I want to encode the following JSON object using Jbuilder. How to do it?

How to format values within the data point tooltips in a RadChart?

telerik number-formatting radchart

I want to format the display of numeric values in an ASP.NET RadChart's tooltips. For example, instead of showing 100000, I want the text to read "1.0e5". For the axes, the property to set is as fo...