Playmaker Forum

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

Title: String Regex Is Match
Post by: Krileon on April 13, 2014, 03:14:31 PM
Just sharing another regex action. This one fires a true/false event based off the regex match or just stores the result of the match (you pick).

[Edit] Youc an get it directly from the Ecosystem (http://j.mp/1Esn1mF)

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

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

namespace HutongGames.PlayMaker.Actions {
[ActionCategory(ActionCategory.String)]
public class StringRegexIsMatch : FsmStateAction {
[RequiredField, UIHint(UIHint.Variable)]
public FsmString stringVariable;
public FsmString regex;
public RegexOptions[] options;
[UIHint(UIHint.Variable)]
public FsmBool storeMatch;
[UIHint(UIHint.Variable)]
public FsmEvent trueEvent;
[UIHint(UIHint.Variable)]
public FsmEvent falseEvent;
public bool everyFrame;

public override void Reset() {
stringVariable = null;
regex = new FsmString { Value = "" };
options = new RegexOptions[0];
storeMatch = null;
trueEvent = null;
falseEvent = 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;
}

storeMatch.Value = Regex.IsMatch( stringVariable.Value, regex.Value, optionsBit );
} else {
storeMatch.Value = Regex.IsMatch( stringVariable.Value, regex.Value );
}

if ( storeMatch.Value ) {
if ( trueEvent != null ) {
Fsm.Event( trueEvent );
}
} else {
if ( falseEvent != null ) {
Fsm.Event( falseEvent );
}
}
}
}
}

For my String Regex Replace action please see the below topic.

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

http://hutonggames.com/playmakerforum/index.php?topic=7006.0
Title: Re: String Regex Is Match
Post by: Uttpd on April 25, 2014, 07:23:22 AM
Thanks.. maybe; Whats REGEX? "Regular Expressions" A brief description would help to understand its usability.

From what I could cof..googlikki cof.. understand, is a way to search characters in a string(s?) of text. Like, find the letter "A" and replace it by "A is no more" or whatever character or group of characters you define.
Is this correct?


Title: Re: String Regex Is Match
Post by: Marsh on April 25, 2014, 02:39:09 PM
REGEX can be used for a ton of things. Some common uses are finding parts of a string, substrings, remove all non characters from a string, removing all characters, removing all numbers, getting strings between strings etc etc etc. It is a insanely handy tool.

Say you had a file of phone numbers and the file was:

NUMBER: 250 -- 305 1982
250 309 3198
NU 250 MBE -- 393 --R 1982

Its all messed up with some terrible formatting etc right? Well Regex could strip all non number characters out and provide a clean file full of nothing but phone numbers.
Title: Re: String Regex Is Match
Post by: jeanfabre on September 08, 2015, 08:11:55 AM
Hi,

 I have now put this action on the Ecosystem (http://j.mp/1Esn1mF)

Thanks :)

 Jean