I would like to compose regexps, that is reusing a regex in a new regex.
Is that possible in Ruby ?
For instance, in order to simplify this assembly-like parsing :
LABELED_INSTR = /(\w+):(movi|addi)\s+(\w+),(\w+),(w+)/
NON_LABELED_INSTR = /(movi|addi)\s+(\w+),(\w+),(w+)/
I would like to resort to :
IMMEDIATE = /(movi|addi)/
But then I don’t know how to share this regex in the two previous ones.
Any hint ?
Sure, regular expressions can be reused (or composed) within other regexes. Here’s an example that combines two regexes to make a third:
Your example is pretty similar. Here, it would be: