简体   繁体   English

Flex正则表达式转换帮助

[英]Flex Regular Expression Conversion Help

I'm having a problem converting a regular expression from Python into Flex. 我在将正则表达式从Python转换为Flex时遇到问题。 My string is something like this: 我的字符串是这样的:

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

Python matches just fine: Python匹配就好了:

>>> 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: 但是当我在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. match始终以null结尾。 What am I doing wrong? 我究竟做错了什么? I'm sure it's obvious to a seasoned Flex programmer... 我相信对于经验丰富的Flex程序员来说这是显而易见的...

Try one of the many Flex regular expression testers out there: 尝试使用众多Flex正则表达式测试器之一:

http://www.idsklijnsma.nl/regexps/ 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. 一方面,您正在使用dotall等,所以您可能想知道Flex为此使用了“ s”标志。 And the "x" flag ignores whitespace, etc. For example, 并且“ x”标志会忽略空格等。例如,

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

works for me on your example. 在您的榜样上对我有用。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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