Project

General

Profile

Actions

Feature #16491

closed

ruby string scan can not support full regex string feature

Added by hakehuang (hake huang) about 4 years ago. Updated about 4 years ago.

Status:
Rejected
Assignee:
-
Target version:
-
[ruby-core:96727]

Description

I have a complex regex string which works fine with match method, but fails with scan. and I think it is because the scan method does not implement full function link match. please see attached test file.

the test match regex is /<testsuites((?!</testsuites>).|\n)+</testsuites>/m


Files

test.rb (1.9 KB) test.rb hakehuang (hake huang), 01/09/2020 07:30 AM

Updated by mame (Yusuke Endoh) about 4 years ago

  • Status changed from Open to Rejected

Try this regex:

/<testsuites(?:(?!<\/testsuites>).|\n)+<\/testsuites>/m

String#scan returns an array of whole matched strings if the regex has no capture, but it returns captured strings ($1, $2, ...) if the regex captures them. Your regex uses (...) which is a capture. Instead, you may want to use (?:...) which does not capture a string.

Actions

Also available in: Atom PDF

Like0
Like0