Author Topic: Regex Replace  (Read 1801 times)

0 Members and 3 Guests are viewing this topic.

Oktane83

  • Jr. Member
  • **
  • Posts: 19
  • Karma: 4
    • View Profile
Regex Replace
« on: March 29, 2014, 11:56:20 PM »
Can't figure this dammn thing out. All I want to do is Replace an "a" with a "b". And an "/" to "/ ".Just adding a space in front.

 :bonk

nime5ter

  • Administrator
  • Hero Member
  • *****
  • Posts: 1999
  • Karma: 61
    • View Profile
    • Getting Started with VoxCommando
Re: Regex Replace
« Reply #1 on: March 30, 2014, 01:05:30 AM »
? Do you mean a space after the slash? In your quotes it looks like there's a space after.

Is the "a" in the middle of a word or on its own?

It's almost always best to post your xml so we can see the context. Maybe the following will help but it's hard to tell without knowing the context.
Code: [Select]
<?xml version="1.0" encoding="utf-16"?>
<!--VoxCommando 1.9.1.9-->
<command id="270" name="a to the b" enabled="true" alwaysOn="False" confirm="False" requiredConfidence="0" loop="False" loopDelay="0" loopMax="0" description="Results.Replace (no regular expression) is sometimes enough, and sometimes easier. Sometimes not.&#xD;&#xA;&#xD;&#xA;The 2nd, &quot;replace with&quot;, parameter in Results.RegExReplace does not take regular expressions. So if you want spaces around your b, put spaces around your b.">
  <action>
    <cmdType>Results.SetLastResult</cmdType>
    <params>
      <param>I am a on my own.</param>
    </params>
    <cmdRepeat>1</cmdRepeat>
  </action>
  <action>
    <cmdType>OSD.ShowText</cmdType>
    <params>
      <param>{LastResult}</param>
      <param>10000</param>
    </params>
    <cmdRepeat>1</cmdRepeat>
  </action>
  <action>
    <cmdType>Results.Replace</cmdType>
    <params>
      <param> a </param>
      <param> b </param>
    </params>
    <cmdRepeat>1</cmdRepeat>
  </action>
  <action>
    <cmdType>OSD.AddText</cmdType>
    <params>
      <param>{LastResult}</param>
    </params>
    <cmdRepeat>1</cmdRepeat>
  </action>
  <action>
    <cmdType>Results.SetLastResult</cmdType>
    <params>
      <param>I am ab when I should be just b. But fab is still fab.</param>
    </params>
    <cmdRepeat>1</cmdRepeat>
  </action>
  <action>
    <cmdType>OSD.AddText</cmdType>
    <params>
      <param>{LastResult}</param>
    </params>
    <cmdRepeat>1</cmdRepeat>
  </action>
  <action>
    <cmdType>Results.RegExReplace</cmdType>
    <params>
      <param>(\sab\s)</param>
      <param> b </param>
    </params>
    <cmdRepeat>1</cmdRepeat>
  </action>
  <action>
    <cmdType>OSD.AddText</cmdType>
    <params>
      <param>Now, {LastResult}</param>
    </params>
    <cmdRepeat>1</cmdRepeat>
  </action>
  <action>
    <cmdType>Results.SetLastResult</cmdType>
    <params>
      <param>Sometimes "results.replace" is/a/better choice than "results.regex".</param>
    </params>
    <cmdRepeat>1</cmdRepeat>
  </action>
  <action>
    <cmdType>OSD.AddText</cmdType>
    <params>
      <param>{LastResult}</param>
    </params>
    <cmdRepeat>1</cmdRepeat>
  </action>
  <action>
    <cmdType>Results.Replace</cmdType>
    <params>
      <param>/</param>
      <param> / </param>
    </params>
    <cmdRepeat>1</cmdRepeat>
  </action>
  <action>
    <cmdType>OSD.AddText</cmdType>
    <params>
      <param>{LastResult}</param>
    </params>
    <cmdRepeat>1</cmdRepeat>
  </action>
</command>
« Last Edit: January 25, 2015, 08:53:44 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)

Oktane83

  • Jr. Member
  • **
  • Posts: 19
  • Karma: 4
    • View Profile
Re: Regex Replace
« Reply #2 on: March 30, 2014, 12:06:47 PM »
Ok ill play around with that when I get off work. Again thank you guys for all the help. This programming, if I can call it that is really fun, but absolutely maddening at the same time. Mostly because I have no idea what I'm doing lol.  :D

jitterjames

  • Administrator
  • Hero Member
  • *****
  • Posts: 7714
  • Karma: 116
    • View Profile
    • VoxCommando
Re: Regex Replace
« Reply #3 on: March 30, 2014, 12:18:07 PM »
This programming, if I can call it that is really fun, but absolutely maddening at the same time. Mostly because I have no idea what I'm doing lol.  :D

That pretty much sums up my life.  ::hmm

garryjw

  • $upporter
  • Contributor
  • *****
  • Posts: 59
  • Karma: 5
    • View Profile
Re: Regex Replace
« Reply #4 on: March 30, 2014, 08:13:13 PM »
...and mine - great quote.