^ISBN[-]?[ dd|-]+
For
^ISBN-?[ dd|-]+
But I think the result will be the same
In this case, []
means []
to match any of the characters specified in []
and is different from []
in classes.
Yes, Ruby's regular expression [-]
matches one character and is equivalent to the regular expression -
.
Although not explicitly written in the Ruby 2.5 document (this or this), hyphens in []
are treated as expressing a range only when [a-z]
.Nonmetacharacters without backslash escape are treated as nonmetacharacters, such as when at the beginning.
For example, the regular expression Reference Blog: Regular Expressions: Symbols that do not need to be escaped within character class [] --Tech Racho [-abc]
matches -
, a
, b
, and c
(Example: Rubular/"https://wandbox.org/permlink/jrOb0pT4Kk6UszvV"rel="norever/norebox>.
© 2024 OneMinuteCode. All rights reserved.