News:

VoxCommando supports plugins for a wide variety of programs and devices. Contact us if you want to create your own.

Main Menu

New feature: Enhanced regex

Started by nime5ter, March 12, 2014, 11:48:58 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

nime5ter

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):

<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 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.
TIPS: POST VC VERSION #. Explain what you want VC to do. Say what you've tried & what happened, or post a video demo. Attach VC log. Link to instructions followed.  Post your command (xml)

macrho

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

jitterjames

I LOVE regex.  Maybe I'm the one person you were referring to.  :D

nime5ter

#3
 :)

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.

TIPS: POST VC VERSION #. Explain what you want VC to do. Say what you've tried & what happened, or post a video demo. Attach VC log. Link to instructions followed.  Post your command (xml)

nime5ter

For anyone who may be interested, here is one of many good introductory video tutorials on using regular expressions. http://www.youtube.com/watch?v=DRR9fOXkfRE

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

TIPS: POST VC VERSION #. Explain what you want VC to do. Say what you've tried & what happened, or post a video demo. Attach VC log. Link to instructions followed.  Post your command (xml)

Autom8It

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!

Kalle

***********  get excited and make things  **********

jitterjames

Quote from: Autom8It on March 13, 2014, 05:31:19 PMbut all the (*.!?).!>1. always confused me.
Hey watch your language, this forum is rated 'G'