[ruby-core:86150] [Ruby trunk Bug#14608] Regexp::union and forward slashes

From: shevegen@...
Date: 2018-03-16 00:21:06 UTC
List: ruby-core #86150
Issue #14608 has been updated by shevegen (Robert A. Heiler).


Interesting. I would have expected them to be the same.

Would be nice if it could be explained in the official docs
too at http://ruby-doc.org/core-2.5.0/Regexp.html#method-c-union

----------------------------------------
Bug #14608: Regexp::union and forward slashes
https://bugs.ruby-lang.org/issues/14608#change-71029

* Author: jason.barnabe (Jason Barnabe)
* Status: Open
* Priority: Normal
* Assignee: 
* Target version: 
* ruby -v: 2.5.0
* Backport: 2.3: UNKNOWN, 2.4: UNKNOWN, 2.5: UNKNOWN
----------------------------------------
When using Regexp::union and a regular expression with a forward slash, there seem to be some inconsistencies.

~~~ ruby
# this is weird
Regexp.union(/\//, '')                  # => /(?-mix:\/)|/
Regexp.union(/\//, '') == /(?-mix:\/)|/ # => false

# here is the difference
Regexp.union(/\//, '').source           # => "(?-mix:\\/)|"
/(?-mix:\/)|/.source                    # => "(?-mix:/)|"
~~~


Previously reported at https://github.com/janosch-x/js_regex/issues/6



-- 
https://bugs.ruby-lang.org/

Unsubscribe: <mailto:ruby-core-request@ruby-lang.org?subject=unsubscribe>
<http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-core>

In This Thread

Prev Next