Author Topic: New feature: Enhanced regex  (Read 5116 times)

0 Members and 1 Guest are viewing this topic.

nime5ter

  • Administrator
  • Hero Member
  • *****
  • Posts: 2012
  • Karma: 61
    • View Profile
    • Getting Started with VoxCommando
New feature: Enhanced regex
« 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.
« Last Edit: March 12, 2014, 11:51:56 PM by nime5ter »
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

  • $upporter
  • Contributor
  • *****
  • Posts: 75
  • Karma: 0
    • View Profile
Re: New feature: Enhanced regex
« Reply #1 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

jitterjames

  • Administrator
  • Hero Member
  • *****
  • Posts: 7715
  • Karma: 116
    • View Profile
    • VoxCommando
Re: New feature: Enhanced regex
« Reply #2 on: March 13, 2014, 09:22:57 AM »
I LOVE regex.  Maybe I'm the one person you were referring to.  :D

nime5ter

  • Administrator
  • Hero Member
  • *****
  • Posts: 2012
  • Karma: 61
    • View Profile
    • Getting Started with VoxCommando
Re: New feature: Enhanced regex
« Reply #3 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.

« Last Edit: March 13, 2014, 10:28:19 AM by nime5ter »
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

  • Administrator
  • Hero Member
  • *****
  • Posts: 2012
  • Karma: 61
    • View Profile
    • Getting Started with VoxCommando
Re: New feature: Enhanced regex
« Reply #4 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

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

  • Newbie
  • *
  • Posts: 1
  • Karma: 1
    • View Profile
Re: New feature: Enhanced regex
« Reply #5 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!

Kalle

  • $upporter
  • Hero Member
  • *****
  • Posts: 2319
  • Karma: 47
    • View Profile
Re: New feature: Enhanced regex
« Reply #6 on: March 13, 2014, 06:40:01 PM »
Haha, I'm with you  :biglaugh
***********  get excited and make things  **********

jitterjames

  • Administrator
  • Hero Member
  • *****
  • Posts: 7715
  • Karma: 116
    • View Profile
    • VoxCommando
Re: New feature: Enhanced regex
« Reply #7 on: March 13, 2014, 08:12:46 PM »
but all the (*.!?).!>1. always confused me.
Hey watch your language, this forum is rated 'G'