简体   繁体   中英

Flex Regular Expression Conversion Help

I'm having a problem converting a regular expression from Python into Flex. My string is something like this:

SELECT "col", othercol,\n "othercol3" FROM doesn'tmatter...

Python matches just fine:

>>> re.search('select(.*?)from', 'SELECT "col", othercol,\n "othercol3" FROM doesn\'tmatter...', re.DOTALL|re.IGNORECASE).groups()[0]

' "col", othercol,\n "othercol3" '

But when I try it in Flex:

var pattern:RegExp = /select(.*?)from/ig;
var match:Array = pattern.exec('SELECT "col", othercol,\n "othercol3" FROM doesn\'tmatter...');
trace(match);

match always ends up null. What am I doing wrong? I'm sure it's obvious to a seasoned Flex programmer...

Try one of the many Flex regular expression testers out there:

http://www.idsklijnsma.nl/regexps/

For one thing, you're using dotall, etc., so you might want to know that Flex use the "s" flag for that. And the "x" flag ignores whitespace, etc. For example,

pattern:RegExp = /select.+?from/gis;

works for me on your example.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM