/** * Compile a regular expression using the JDK implementation */ @Test public void testMatcher() { final RegExp regexp = new RegExpFactory().compile("f(o)o", ""); final RegExpMatcher matcher = regexp.match("foo"); assertNotNull(matcher); assertTrue(matcher.search(0)); assertEquals(matcher.getInput(), "foo"); assertEquals(matcher.groupCount(), 1); assertEquals(matcher.group(), "foo"); assertEquals(matcher.start(), 0); assertEquals(matcher.end(), 3); assertEquals(matcher.group(1), "o"); assertEquals(matcher.start(1), 1); assertEquals(matcher.end(1), 2); }
NativeRegExp(final String input, final String flagString, final Global global) { this(global); try { this.regexp = RegExpFactory.create(input, flagString); } catch (final ParserException e) { // translate it as SyntaxError object and throw it e.throwAsEcmaException(); throw new AssertionError(); //guard against null warnings below } this.setLastIndex(0); }
NativeRegExp(final String input, final String flagString, final Global global, final ScriptObject proto) { super(proto, $nasgenmap$); try { this.regexp = RegExpFactory.create(input, flagString); } catch (final ParserException e) { // translate it as SyntaxError object and throw it e.throwAsEcmaException(); throw new AssertionError(); //guard against null warnings below } this.globalObject = global; this.setLastIndex(0); }