Closed alexwenbj closed 4 years ago
That’s an interesting behavior difference. However, the behavior of XRegExp.split’s limit argument is intentional. It follows the behavior of JavaScript’s String.prototype.split. See https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/split.
So sad.Maybe it is better be compatible with PCRE.
For split(), in perl,the
LIMIT
means:split /PATTERN/,EXPR,LIMIT
But in xregexp, it just means return how much elements of the split array. In PCRE mode(include Perl/PHP/Python),the limit affects the split ACTION In xregexp,the limit affects the return array elements number.
In Perl:
print join(" ",split(/:/, ':a:b::c', 3))
=> a b::c In xregexp:=>["", "a", "b"]
Ref: https://perldoc.perl.org/functions/split.html https://www.php.net/manual/en/function.preg-split.php https://docs.python.org/3/library/re.html