Skip to content

#scan_until behaves differently with Regexp and String patterns #131

@andrykonchin

Description

@andrykonchin

Wondering whether it's a correct behaviour of recently introduced matching with a String pattern. Use Ruby 3.4.1 and strscan v3.1.2

String pattern:

require 'strscan' scanner = StringScanner.new("こんにちは") scanner.scan_until("ち") # => "こんにち" scanner.pre_match # => "" scanner.matched # => "こんにち" scanner.post_match # => "は"

Regexp pattern:

require 'strscan' scanner = StringScanner.new("こんにちは") scanner.scan_until(/ち/) # => "こんにち" scanner.pre_match # => "こんに" scanner.matched # => "ち" scanner.post_match # => "は"

When pattern is String then #pre_match and #matched work differently - #matched returns a substring from the current position to the end of a found substring and #pre_match returns "".

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions