Is it possible to concat two regex variables in Ruby?
r1 = /my_str/
r2 = /my_str1/
r3 = r1+r2
Can anyone give any suggestions?
Any two regular expressions a and b can be concatenated. The result is a regular expression which matches a string if a matches some amount of the beginning of that string and b matches the rest of the string.
To concatenate a regular expression in JavaScript, you can use a combination of the + operator and the RegExp() class as shown below. You need to combine both the RegExp source (the string representation of the RegExp) and flags (options for the RegExp). You are responsible for removing duplicate flags.
A flag is an optional parameter to a regex that modifies its behavior of searching. A flag changes the default searching behavior of a regular expression. It makes a regex search in a different way. A flag is denoted using a single lowercase alphabetic character.
Regexp::union
r1 = /my_str/
r2 = /my_str1/
r3 = Regexp.union(r1, r2)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With