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