// Copyright 2015 the V8 project authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. // Simple fixed-length matches. assertEquals(["a"], "a".match(/^.(?<=a)/)); assertNull("b".match(/^.(?<=a)/)); assertEquals(["foo"], "foo1".match(/^f..(?<=.oo)/)); assertEquals(["foo"], "foo2".match(/^f\w\w(?<=\woo)/)); assertNull("boo".match(/^f\w\w(?<=\woo)/)); assertNull("fao".match(/^f\w\w(?<=\woo)/)); assertNull("foa".match(/^f\w\w(?<=\woo)/)); assertEquals(["def"], "abcdef".match(/(?<=abc)\w\w\w/)); assertEquals(["def"], "abcdef".match(/(?<=a.c)\w\w\w/)); assertEquals(["def"], "abcdef".match(/(?<=a\wc)\w\w\w/)); assertEquals(["cde"], "abcdef".match(/(?<=a[a-z])\w\w\w/)); assertEquals(["def"], "abcdef".match(/(?<=a[a-z][a-z])\w\w\w/)); assertEquals(["def"], "abcdef".match(/(?<=a[a-z]{2})\w\w\w/)); assertEquals(["bcd"], "abcdef".match(/(?<=a{1})\w\w\w/)); assertEquals(["cde"], "abcdef".match(/(?<=a{1}b{1})\w\w\w/)); assertEquals(["def"], "abcdef".match(/(?<=a{1}[a-z]{2})\w\w\w/)); // Variable-length matches. assertEquals(["def"], "abcdef".match(/(?<=[a|b|c]*)[^a|b|c]{3}/)); assertEquals(["def"], "abcdef".match(/(?<=\w*)[^a|b|c]{3}/)); // Start of line matches. assertEquals(["def"], "abcdef".match(/(?<=^abc)def/)); assertEquals(["def"], "abcdef".match(/(?<=^[a-c]{3})def/)); assertEquals(["def"], "abcabcdef".match(/(?<=^[a-c]{6})def/)); assertEquals(["def"], "xyz\nabcdef".match(/(?<=^[a-c]{3})def/m)); assertEquals(["ab", "cd", "efg"], "ab\ncd\nefg".match(/(?<=^)\w+/gm)); assertEquals(["ab", "cd", "efg"], "ab\ncd\nefg".match(/\w+(?<=$)/gm)); assertEquals(["ab", "cd", "efg"], "ab\ncd\nefg".match(/(?<=^)\w+(?<=$)/gm)); assertNull("abcdef".match(/(?<=^[^a-c]{3})def/)); assertNull("foooo".match(/"^foooo(?<=^o+)$/)); assertNull("foooo".match(/"^foooo(?<=^o*)$/)); assertEquals(["foo"], "foo".match(/^foo(?<=^fo+)$/)); assertEquals(["foooo"], "foooo".match(/^foooo(?<=^fo*)/)); assertEquals(["foo", "f"], "foo".match(/^(f)oo(?<=^\1o+)$/)); assertEquals(["foo", "f"], "foo".match(/^(f)oo(?<=^\1o+)$/i)); assertEquals(["foo\u1234", "f"], "foo\u1234".match(/^(f)oo(?<=^\1o+).$/i)); assertEquals(["def"], "abcdefdef".match(/(?<=^\w+)def/)); assertEquals(["def", "def"], "abcdefdef".match(/(?<=^\w+)def/g)); // Word boundary matches. assertEquals(["def"], "abc def".match(/(?<=\b)[d-f]{3}/)); assertEquals(["def"], "ab cdef".match(/(?<=\B)\w{3}/)); assertEquals(["def"], "ab cdef".match(/(?<=\B)(?<=c(?<=\w))\w{3}/)); assertNull("abcdef".match(/(?<=\b)[d-f]{3}/)); // Negative lookbehind. assertEquals(["abc"], "abcdef".match(/(?