This is a little bit hard to explain, so I'll skip the circumstances that led me to needing this particular solution and just skip straight ahead to my problem.
I'm using regex triggers with named groups, and there are some special cases in which it would be very convenient if I could give one or several of the named groups in the regex default values, even if they are never present in the pattern as actual catching groups. Is this possible?
For example, input normally looks like this:
You crave bread!
You crave wine!
..so I use a pattern like '^You crave (?<craving>.*?)!$' and things work just fine.
But in some special cases, it looks like this:
You crave OMNOMNOM crumbly goodness!
..in which case I would like to be able to use a trigger like '^You crave OMNOMNOM crumbly goodness!$' BUT have the rest of the trigger evaluate as if the capture-group 'craving' had matched 'cookie'. This seems like something an advanced feature of regex might be able to pull off, but how? Am I the only one to ever have had this need?
To further clarify, I imagine such a pattern might look something like '(?assign:<craving>=cookie)^You crave OMNOMNOM crumbly goodness!$', giving the capture group a initial value to be used in case there are no other matches, or something like that.
( Of course I'm aware that there are many other possible workarounds I could use, but this is just a simplified example. In my real scenario it would simply be a lot more convenient if it were possible to do things as described above, but is that even possible? )
I'm using regex triggers with named groups, and there are some special cases in which it would be very convenient if I could give one or several of the named groups in the regex default values, even if they are never present in the pattern as actual catching groups. Is this possible?
For example, input normally looks like this:
You crave bread!
You crave wine!
..so I use a pattern like '^You crave (?<craving>.*?)!$' and things work just fine.
But in some special cases, it looks like this:
You crave OMNOMNOM crumbly goodness!
..in which case I would like to be able to use a trigger like '^You crave OMNOMNOM crumbly goodness!$' BUT have the rest of the trigger evaluate as if the capture-group 'craving' had matched 'cookie'. This seems like something an advanced feature of regex might be able to pull off, but how? Am I the only one to ever have had this need?
To further clarify, I imagine such a pattern might look something like '(?assign:<craving>=cookie)^You crave OMNOMNOM crumbly goodness!$', giving the capture group a initial value to be used in case there are no other matches, or something like that.
( Of course I'm aware that there are many other possible workarounds I could use, but this is just a simplified example. In my real scenario it would simply be a lot more convenient if it were possible to do things as described above, but is that even possible? )