简体   繁体   中英

Differences between regular expressions in Java and ECMA-262 (AS, JS)

I need to convert Java regular expressions into Actionscript regular expressions.

There apparently aren't any premade converters, so I'm trying to write one myself. Is there any resource that'd list all the differences?

I'm aware of regular-expressions.info, but there doesn't seem to be a comprehensive listing of differences there.

Thanks

I don't know of any existing converter, but if your target is specifically ActionScript and not just any ECMA-262 implementation, the job could be easier than you expected. AS3 is powered by PCRE , same as PHP's preg_ functions, so it supports lookbehind, atomic groups and possessive quantifiers, same as Java. It also supports Java's dotall and extended modes in addition to JS's ignore-case and multiline . It supports the inline modifier syntax ( (?imsx) ) as well.

PCRE's Unicode support is better than Java's, but unfortunately, I don't think that's included in ActionScript. The Unicode functionality seems to be explicitly tied to the character encoding, which is UTF-8 in PCRE; I believe ActionScript uses UTF-16 in accordance with ECMA-262. Anyway, its Unicode support seems to be minimal, same as JavaScript's.

Here is a breakdown:

java.util.regex                                  RegExp.prototype
Character class set operations
(?#…) comment patterns
Named capture
The /y (sticky) modifier
The /x (extended) modifier
\u10000+ Codepoints
Possessive quantifiers
Quotation
Exception Handling
Linebreak matcher

References

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