mirror of
https://github.com/ruby/ruby.git
synced 2026-10-29 00:46:26 +08:00
(https://github.com/ruby/strscan/pull/203) They don't work in included markdown and also need a leading `:` <img width="791" height="442" alt="grafik" src="https://github.com/user-attachments/assets/eca5d4c2-9597-4c58-a0cc-a4e2c9109992" /> https://github.com/ruby/strscan/commit/b504b3b0ad
1.1 KiB
1.1 KiB
Attempts to [match][17] the given pattern
anywhere (at any [position][2]) in the [target substring][3].
If the match attempt succeeds:
- Sets [match values][9].
- Sets the [byte position][2] to the end of the matched substring; may adjust the [character position][7].
- Returns the size of the matched substring.
scanner = StringScanner.new(HIRAGANA_TEXT)
scanner.string # => "こんにちは"
scanner.pos = 6
scanner.skip_until(/ち/) # => 6
put_match_values(scanner)
# Basic match values:
# matched?: true
# matched_size: 3
# pre_match: "こんに"
# matched : "ち"
# post_match: "は"
# Captured match values:
# size: 1
# captures: []
# named_captures: {}
# values_at: ["ち", nil]
# []:
# [0]: "ち"
# [1]: nil
put_situation(scanner)
# Situation:
# pos: 12
# charpos: 4
# rest: "は"
# rest_size: 3
If the match attempt fails:
- Clears match values.
- Returns
nil. - Does not update positions.
scanner.skip_until(/nope/) # => nil
match_values_cleared?(scanner) # => true