Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it possible to concat two regex variables?

Tags:

regex

ruby

Is it possible to concat two regex variables in Ruby?

r1 = /my_str/
r2 = /my_str1/
r3 = r1+r2

Can anyone give any suggestions?

like image 447
Swapnil Avatar asked Jan 18 '17 07:01

Swapnil


People also ask

Can you concatenate regex?

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.

How to combine two regular expressions in JavaScript?

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.

What are regex 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.


1 Answers

Regexp::union

r1 = /my_str/
r2 = /my_str1/
r3 = Regexp.union(r1, r2)
like image 145
steenslag Avatar answered Oct 11 '22 14:10

steenslag