Bug #19273
closed[Regexp] regexp does not match expected
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.
Updated by mrkn (Kenta Murata) almost 2 years ago
I performed git bisect and found the first bad commit is 37613fea1657b1a0732501657275bc03e8e0ebc4.
Updated by mrkn (Kenta Murata) almost 2 years ago
- Assignee set to make_now_just (Hiroya Fujinami)
Updated by taichi730 (Taichi Ishitani) almost 2 years ago
This pattern shows a binary|decimal|hexadecimal value splitted by : character.
decimal only and decimal|hexadecimal patterns match expectedly.
decimal only pattern:
irb(main):019:0> pattern = /(?-mix:[+-]?(?:[1-9]_?(?:\d_?)*)?\d)(?::(?-mix:[+-]?(?:[1-9]_?(?:\d_?)*)?\d)){0,3}/
=> /(?-mix:[+-]?(?:[1-9]_?(?:\d_?)*)?\d)(?::(?-mix:[+-]?(?:[1-9]_?(?:\d_?)*)?\d)){0,3}/
irb(main):020:0> "10:0:0".match(pattern)
=> #<MatchData "10:0:0">
decimal|hex pattern:
irb(main):021:0> = /(?-mix:(?-mix:[+-]?(?:[1-9]_?(?:\d_?)*)?\d)|(?i-mx:[+-]?0x\h(?:_?\h)*))(?::(?-mix:(?-mix:[+-]?(?:[1-irb(main):021:0> pattern = /(?-mix:(?-mix:[+-]?(?:[1-9]_?(?:\d_?)*)?\d)|(?i-mx:[+-]?0x\h(?:_?\h)*))(?::(?-mix:(?-mix:[+-]?(?:[1-9]_?(?:\d_?)*)?\d)|(?i-mx:[+-]?0x\h(?:_?\h)*))){0,3}/
=> /(?-mix:(?-mix:[+-]?(?:[1-9]_?(?:\d_?)*)?\d)|(?i-mx:[+-]?0x\h(?:_?\h)*))(?::(?-mix:(?-mix:[+-]?(?:[1-9]_?(?:\d_?...
irb(main):022:0> "10:0:0".match(pattern)
=> #<MatchData "10:0:0">
But binary|decimal pattern does not.
irb(main):023:0> pattern = /(?-mix:(?i-mx:[+-]?0b[01](?:_?[01])*)|(?-mix:[+-]?(?:[1-9]_?(?:\d_?)*)?\d))(?::(?-mix:(?i-mx:[+-]?0b[01](?:_?[01])*)|(?-mix:[+-]?(?:[1-9]_?(?:\d_?)*)?\d))){0,3}/
=> /(?-mix:(?i-mx:[+-]?0b[01](?:_?[01])*)|(?-mix:[+-]?(?:[1-9]_?(?:\d_?)*)?\d))(?::(?-mix:(?i-mx:[+-]?0b[01](?:_?[0...
irb(main):024:0> "10:0:0".match(pattern)
=> #<MatchData "10">
Updated by taichi730 (Taichi Ishitani) almost 2 years ago
Pattern using *
quantifier instead of {0,3}
quantifier matches expactedly.
irb(main):027: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)*)))*/
=> /(?-mix:(?i-mx:[+-]?0b[01](?:_?[01])*)|(?-mix:[+-]?(?:[1-9]_?(?:\d_?)*)?\d)|(?i-mx:[+-]?0x\h(?:_?\h)*))(?::(?-mi...
irb(main):028:0> "10:0:0".match(pattern)
=> #<MatchData "10:0:0">
Updated by duerst (Martin Dürst) almost 2 years ago
- Subject changed from [Regexp] regexp does not does not match expected to [Regexp] regexp does not match expected
Updated by make_now_just (Hiroya Fujinami) almost 2 years ago
PR #7035 for fixing the bug is created.
Updated by nagachika (Tomoyuki Chikanaga) almost 2 years ago
- Status changed from Open to Closed
- Backport changed from 2.7: UNKNOWN, 3.0: UNKNOWN, 3.1: UNKNOWN, 3.2: UNKNOWN to 2.7: DONTNEED, 3.0: DONTNEED, 3.1: DONTNEED, 3.2: REQUIRED
merged at b726d60c986bf951d13e7a2ab5f5e58f58657b03
Updated by naruse (Yui NARUSE) almost 2 years ago
- Backport changed from 2.7: DONTNEED, 3.0: DONTNEED, 3.1: DONTNEED, 3.2: REQUIRED to 2.7: DONTNEED, 3.0: DONTNEED, 3.1: DONTNEED, 3.2: DONE
ruby_3_2 a7d467a792c644a7260d6560ea2002fdb8ff6de3 merged revision(s) b726d60c986bf951d13e7a2ab5f5e58f58657b03.