News:

Would you like to say "Thanks!" for extra support or new features that we provided? Donations are gratefully accepted.

Main Menu

Need help with RegEx Pattern

Started by Aniv_D, July 27, 2019, 03:01:14 AM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

Aniv_D

Hello jitterjames! could you help with the pattern.
There is a Custom file.txt from which to find some text.
I made this pattern:
<(.*?)>\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:
<?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

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:
<(\w*?)>\s*<Primary\sDevice="Keyboard"\sKey="Key_(\w*?)"\s/>\s*<Secondary\sDevice="Keyboard"\sKey="Key_(\w*?)"\s/>

jitterjames

#2
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.

Aniv_D

Thank you very much for your help, jitterjames