1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68
|
// Copyright (C) 2016 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-regular-expressions-patterns
es6id: B.1.4
description: Quantifiable assertions `?=` ("followed by")
info: |
Term[U] ::
[~U] QuantifiableAssertion Quantifier
QuantifiableAssertion ::
( ?= Disjunction )
( ?! Disjunction )
The production Term::QuantifiableAssertionQuantifier evaluates the same as
the production Term::AtomQuantifier but with QuantifiableAssertion
substituted for Atom.
The production Assertion::QuantifiableAssertion evaluates by evaluating
QuantifiableAssertion to obtain a Matcher and returning that Matcher.
Assertion (21.2.2.6) evaluation rules for the Assertion::(?=Disjunction)
and Assertion::(?!Disjunction) productions are also used for the
QuantifiableAssertion productions, but with QuantifiableAssertion
substituted for Assertion.
---*/
var match;
match = /.(?=Z)*/.exec('a bZ cZZ dZZZ eZZZZ');
assert.sameValue(match[0], 'a', 'quantifier: *');
match = /.(?=Z)+/.exec('a bZ cZZ dZZZ eZZZZ');
assert.sameValue(match[0], 'b', 'quantifier: +');
match = /.(?=Z)?/.exec('a bZ cZZ dZZZ eZZZZ');
assert.sameValue(match[0], 'a', 'quantifier: ?');
match = /.(?=Z){2}/.exec('a bZ cZZ dZZZ eZZZZ');
assert.sameValue(match[0], 'b', 'quantifier: { DecimalDigits }');
match = /.(?=Z){2,}/.exec('a bZ cZZ dZZZ eZZZZ');
assert.sameValue(match[0], 'b', 'quantifier: { DecimalDigits , }');
match = /.(?=Z){2,3}/.exec('a bZ cZZ dZZZ eZZZZ');
assert.sameValue(
match[0], 'b', 'quantifier: { DecimalDigits , DecimalDigits }'
);
match = /.(?=Z)*?/.exec('a bZ cZZ dZZZ eZZZZ');
assert.sameValue(match[0], 'a', 'quantifier: * ?');
match = /.(?=Z)+?/.exec('a bZ cZZ dZZZ eZZZZ');
assert.sameValue(match[0], 'b', 'quantifier: + ?');
match = /.(?=Z)??/.exec('a bZ cZZ dZZZ eZZZZ');
assert.sameValue(match[0], 'a', 'quantifier: ? ?');
match = /.(?=Z){2}?/.exec('a bZ cZZ dZZZ eZZZZ');
assert.sameValue(match[0], 'b', 'quantifier: { DecimalDigits } ?');
match = /.(?=Z){2,}?/.exec('a bZ cZZ dZZZ eZZZZ');
assert.sameValue(match[0], 'b', 'quantifier: { DecimalDigits , } ?');
match = /.(?=Z){2,3}?/.exec('a bZ cZZ dZZZ eZZZZ');
assert.sameValue(
match[0], 'b', 'quantifier: { DecimalDigits , DecimalDigits } ?'
);
|