From: "taichi730 (Taichi Ishitani) via ruby-core" Date: 2022-12-28T03:39:38+00:00 Subject: [ruby-core:111468] [Ruby master Bug#19273] [Regexp] regexp does not does not match expected Issue #19273 has been updated by taichi730 (Taichi Ishitani). 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) => # ``` 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) => # ``` 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) => # ``` ---------------------------------------- Bug #19273: [Regexp] regexp does not does not match expected https://bugs.ruby-lang.org/issues/19273#change-100839 * Author: taichi730 (Taichi Ishitani) * Status: Open * Priority: Normal * Assignee: make_now_just (Hiroya Fujinami) * ruby -v: ruby 3.2.0 (2022-12-25 revision a528908271) [x86_64-linux] * Backport: 2.7: UNKNOWN, 3.0: UNKNOWN, 3.1: UNKNOWN, 3.2: UNKNOWN ---------------------------------------- A regexp pattern does not match expected with Ruby 3.2. Ruby 3.2 ``` ruby 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) #=> # "0:0:0".match(pattern) #=> # ``` String "10.0.0" is only partially matched but not all of it. Ruby 3.1.0: ```ruby 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) #=> # "0:0:0".match(pattern) #=> # ``` Both strings matches with the regexp wholy. -- https://bugs.ruby-lang.org/ ______________________________________________ ruby-core mailing list -- ruby-core@ml.ruby-lang.org To unsubscribe send an email to ruby-core-leave@ml.ruby-lang.org ruby-core info -- https://ml.ruby-lang.org/mailman3/postorius/lists/ruby-core.ml.ruby-lang.org/