Author Topic: Need help with RegEx Pattern  (Read 2159 times)

0 Members and 1 Guest are viewing this topic.

Aniv_D

  • Jr. Member
  • **
  • Posts: 42
  • Karma: 10
    • View Profile
Need help with RegEx Pattern
« on: July 27, 2019, 03:01:14 AM »
Hello jitterjames! could you help with the pattern.
There is a Custom file.txt from which to find some text.
I made this pattern:
Code: [Select]
<(.*?)>\n\t\t<Primary\sDevice="Keyboard"\sKey="Key_(.*?)"\s/>\n\t\t<Secondary\sDevice="Keyboard"\sKey="Key_(.*?)"\s/>and it seems to work in Regular Expression Helper, but for some reason it does not want to work when executing the command. could you tell me what could be wrong

here is the command code:
Code: [Select]
<?xml version="1.0" encoding="utf-16"?>
<!--VoxCommando 2.2.4.7-->
<commandGroup open="True" name="Test" enabled="True" prefix="" priority="0" requiredProcess="" description="">
  <command id="1337" name="find and save match's" enabled="true" alwaysOn="False" confirm="False" requiredConfidence="0" loop="False" loopDelay="0" loopMax="0" description="">
    <action>
      <cmdType>File.Read</cmdType>
      <params>
        <param>D:\Custom.txt</param>
      </params>
      <cmdRepeat>1</cmdRepeat>
    </action>
    <action>
      <cmdType>Results.RegEx</cmdType>
      <params>
        <param>&lt;(.*?)&gt;\n\t\t&lt;Primary\sDevice="Keyboard"\sKey="Key_(.*?)"\s/&gt;\n\t\t&lt;Secondary\sDevice="Keyboard"\sKey="Key_(.*?)"\s/&gt;</param>
        <param />
        <param>{LastResult}</param>
      </params>
      <cmdRepeat>1</cmdRepeat>
    </action>
    <loop>
      <loopParams>
        <from>1</from>
        <to>{#M}</to>
      </loopParams>
      <loopActions>
        <action>
          <cmdType>File.AppendLine</cmdType>
          <params>
            <param>D:\Custom_Result.txt</param>
            <param>{Match.{j}.1}</param>
          </params>
          <cmdRepeat>1</cmdRepeat>
        </action>
      </loopActions>
    </loop>
  </command>
</commandGroup>

jitterjames

  • Administrator
  • Hero Member
  • *****
  • Posts: 7715
  • Karma: 116
    • View Profile
    • VoxCommando
Re: Need help with RegEx Pattern
« Reply #1 on: July 27, 2019, 08:37:50 AM »
It is a very interesting question.  I am not sure why it does work in the RegEx tool because I don't think it should!

As far as I know the correct way to do this is using RegExSingle.


With RegExSingle the following pattern should work:
Code: [Select]
<(\w*?)>\s*<Primary\sDevice="Keyboard"\sKey="Key_(\w*?)"\s/>\s*<Secondary\sDevice="Keyboard"\sKey="Key_(\w*?)"\s/>

jitterjames

  • Administrator
  • Hero Member
  • *****
  • Posts: 7715
  • Karma: 116
    • View Profile
    • VoxCommando
Re: Need help with RegEx Pattern
« Reply #2 on: July 27, 2019, 10:12:55 AM »
I think I know what is happening.

The text file contains carriage return and line feed characters at the end of each line.

When the file is loaded into the Regex tool text box the carriage returns are being stripped out.

So your pattern will probably give you matches in your macro if you use \r\n instead of \r (but then this pattern will not work in the tool window.

I have to investigate.
« Last Edit: July 27, 2019, 10:46:30 AM by nime5ter »

Aniv_D

  • Jr. Member
  • **
  • Posts: 42
  • Karma: 10
    • View Profile
Re: Need help with RegEx Pattern
« Reply #3 on: July 27, 2019, 10:41:03 AM »
Thank you very much for your help, jitterjames