Project

General

Profile

Actions

Bug #19273

closed

[Regexp] regexp does not match expected

Added by taichi730 (Taichi Ishitani) almost 2 years ago. Updated almost 2 years ago.

Status:
Closed
Target version:
-
ruby -v:
ruby 3.2.0 (2022-12-25 revision a528908271) [x86_64-linux]
[ruby-core:111465]

Description

A regexp pattern does not match expected with Ruby 3.2.

Ruby 3.2

pattern = /(?-mix:(?i-mx:[+-]?0b[01](?:_?[01])*)|(?-mix:[+-]?(?:[1-9]_?(?:\d_?)*)?\d)|(?i-mx:[+-]?0x\h(?:_?\h)*))(?::(?-mix:(?i-mx:[+-]?0b[01](?:_?[01])*)|(?-mix:[+-]?(?:[1-9]_?(?:\d_?)*)?\d)|(?i-mx:[+-]?0x\h(?:_?\h)*))){0,3}/
"10:0:0".mathc(pattern) #=> #<MatchData "10">
"0:0:0".match(pattern) #=> #<MatchData "0:0:0">

String "10.0.0" is only partially matched but not all of it.

Ruby 3.1.0:

pattern = /(?-mix:(?i-mx:[+-]?0b[01](?:_?[01])*)|(?-mix:[+-]?(?:[1-9]_?(?:\d_?)*)?\d)|(?i-mx:[+-]?0x\h(?:_?\h)*))(?::(?-mix:(?i-mx:[+-]?0b[01](?:_?[01])*)|(?-mix:[+-]?(?:[1-9]_?(?:\d_?)*)?\d)|(?i-mx:[+-]?0x\h(?:_?\h)*))){0,3}/
"10:0:0".match(pattern) #=> #<MatchData "10:0:0">
"0:0:0".match(pattern) #=> #<MatchData "0:0:0">

Both strings matches with the regexp wholy.

Actions

Also available in: Atom PDF

Like0
Like0Like0Like0Like0Like0Like1Like0Like0