Playmaker Forum

PlayMaker Updates & Downloads => Share New Actions => Topic started by: Krileon on April 13, 2014, 02:57:31 PM

Title: String Regex Replace
Post by: Krileon on April 13, 2014, 02:57:31 PM
I wanted to use REGEX for my replacement usage so I created a String Regex Replace. Thought I'd go ahead and share it as it's a pretty generic and useful action.

[edit] It's now available directly on the Ecosystem (http://j.mp/1Esn1mF)

StringRegexReplace (https://github.com/jeanfabre/PlayMakerCustomActions_U4/blob/master/Assets/PlayMaker%20Custom%20Actions/String/StringRegexReplace.cs)

Code: [Select]
using UnityEngine;
using System.Text.RegularExpressions;

namespace HutongGames.PlayMaker.Actions {
[ActionCategory(ActionCategory.String)]
public class StringRegexReplace : FsmStateAction {
[RequiredField, UIHint(UIHint.Variable)]
public FsmString stringVariable;
public FsmString regex;
public FsmString with;
public RegexOptions[] options;
[RequiredField, UIHint(UIHint.Variable)]
public FsmString storeResult;
public bool everyFrame;

public override void Reset() {
stringVariable = null;
regex = new FsmString { Value = "" };
with = new FsmString { Value = "" };
options = new RegexOptions[0];
storeResult = null;
everyFrame = false;
}

public override void OnEnter() {
DoAction();

if ( ! everyFrame ) {
Finish();
}
}

public override void OnUpdate() {
DoAction();
}

void DoAction() {
if ( options.Length > 0 ) {
RegexOptions optionsBit = 0;

foreach ( RegexOptions option in options ) {
optionsBit |= option;
}

storeResult.Value = Regex.Replace( stringVariable.Value, regex.Value, with.Value, optionsBit );
} else {
storeResult.Value = Regex.Replace( stringVariable.Value, regex.Value, with.Value );
}
}
}
}

I'll probably be adding other regex actions as well such as Match. Anyway, hope others find as much use out of this as I have.
Title: Re: String Regex Replace
Post by: Krileon on April 13, 2014, 03:15:13 PM
Ok, created a String Regex Is Match action, which you can find below.

http://hutonggames.com/playmakerforum/index.php?topic=7005.0
Title: Re: String Regex Replace
Post by: Krileon on April 13, 2014, 03:25:57 PM
New String Regex Match action can be found below.

http://hutonggames.com/playmakerforum/index.php?topic=7006.0
Title: Re: String Regex Replace
Post by: jeanfabre on September 08, 2015, 08:36:19 AM
Hi,

 Thanks for this. I made it available on the Ecosystem (http://j.mp/1Esn1mF) for convenience.

 Bye,

 Jean