Teal TealUI

正则表达式加强util/xRegExp

提供更多功能的正则表达式。

import XRegExp from "util/xRegExp";

var date = XRegExp('(?<year>  [0-9]{4} ) -?  # year  \n' +
        '(?<month> [0-9]{2} ) -?  # month \n' +
        '(?<day>   [0-9]{2} )     # day     ', 'x');

XRegExp.exec('2012-06-10', date).year; // => '2012'

XRegExp.replace('2012-06-10', date, '${month}/${day}/${year}'); // => '06/10/2012'

XRegExp.matchChain('<a href="http://xregexp.com/api/">XRegExp</a><a href="http://www.google.com/">Google</a>', [
    {regex: /<a href="([^"]+)">/i, backref: 1},
    {regex: XRegExp('(?i)^https?://(?<domain>[^/?#]+)'), backref: 'domain'}
]); // => ['xregexp.com', 'www.google.com']
另参考