VoxCommando

New Features and Feature Requests => Version 2 updates => Topic started by: nime5ter on March 12, 2014, 11:48:58 PM

Title: New feature: Enhanced regex
Post by: nime5ter on March 12, 2014, 11:48:58 PM
Granted, I am not an objective observer, but I have just been testing a new regex feature that's been added in 1.914 (i.e. v2 alpha) and it is a *huge* leap forward. Thought I'd mention it.

Multiple captures in a single match have been available for a while. But now we can access the individual captures from each match. This is a big advantage and allows for much more streamlined commands.

Example: I have media server that stores metadata about my library in xml. Each media file has an ID that the media player needs in order to know which file to play. I obviously want to be able to ask VC to play my media by title.

The library xml data looks like (entirely fake):
Code: [Select]
<video database>
<video><movieID="4040" type="movie" title="the 4 on the floor film iv" review="Film in which four are on the floor and five and are doing the handjive while six are picking up sticks." year="2014"</video>
<video><movieID="2345" type="movie" title="no no no" review="Very negative film about negativity." year="1955"</video>
</video database>

I want to create payloadXML where the film title is associated with the movie id.

I can use the pattern
Code: [Select]
movieID="(.*?)".*?title="(.*?)" as we've been able to do for some time in version 1.

{Match.1} then will combine "4040" and "the 4 on the floor film iv".

It's useful that we can initially grab them together, because they're an associated pair. But: For payload xml, what I want is to then be able to separately access and store {Match.1.1} (value) and {Match.1.2} (phrase).

This is now possible in one easy step, whereas before we had to jump through a few hoops, save results as variables and so on.

Since I use regular expressions a lot, I am pretty pleased about this improvement.
Title: Re: New feature: Enhanced regex
Post by: macrho on March 13, 2014, 07:30:59 AM
Cool feature. I've only met one person who liked regular expressions, I use them when necessary but it feels like pulling my teeth out very slowly  :bonk
Title: Re: New feature: Enhanced regex
Post by: jitterjames on March 13, 2014, 09:22:57 AM
I LOVE regex.  Maybe I'm the one person you were referring to.  :D
Title: Re: New feature: Enhanced regex
Post by: nime5ter on March 13, 2014, 09:25:58 AM
 :)

It gets easier with practice, and I find them a fun puzzle.

Arguably, scrape + regex is one of the most powerful tools we have in VoxCommando to control the widest variety of devices. Rather than requiring a plugin for each of the hundreds of different possible devices out there, it allows us to use the tools we have.

So, for example, Nodo very quickly came up with a clever solution for his Domoticz home automation system: http://voxcommando.com/forum/index.php?topic=1433.msg12443#msg12443 .

Now he (she? I'm falling for the usual trap!) can do the same thing, but more elegantly.

Title: Re: New feature: Enhanced regex
Post by: nime5ter on March 13, 2014, 09:47:49 AM
For anyone who may be interested, here is one of many good introductory video tutorials on using regular expressions.


In the Results.Regex action description, James also links to this helpful cheatsheet that we use all the time: http://www.mikesdotnetting.com/Article/46/CSharp-Regular-Expressions-Cheat-Sheet

Title: Re: New feature: Enhanced regex
Post by: Autom8It on March 13, 2014, 05:31:19 PM
I too love using regex. It lets you add a much more human touch to the commands and the possibilities are endless, but all the (*.!?).!>1. always confused me. Thanks for the links nime5ter and James!
Title: Re: New feature: Enhanced regex
Post by: Kalle on March 13, 2014, 06:40:01 PM
Haha, I'm with you  :biglaugh
Title: Re: New feature: Enhanced regex
Post by: jitterjames on March 13, 2014, 08:12:46 PM
but all the (*.!?).!>1. always confused me.
Hey watch your language, this forum is rated 'G'