playMaker

Author Topic: String Regex Is Match  (Read 5379 times)

Krileon

  • Full Member
  • ***
  • Posts: 107
String Regex Is Match
« 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

StringRegexMatch

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
« Last Edit: September 08, 2015, 08:23:43 AM by jeanfabre »

Krileon

  • Full Member
  • ***
  • Posts: 107
Re: String Regex Is Match
« Reply #1 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

Uttpd

  • Junior Playmaker
  • **
  • Posts: 70
Re: String Regex Is Match
« Reply #2 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?



Marsh

  • Full Member
  • ***
  • Posts: 227
  • Comfort the disturbed, disturb the comfortable
Re: String Regex Is Match
« Reply #3 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.

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15500
  • Official Playmaker Support
Re: String Regex Is Match
« Reply #4 on: September 08, 2015, 08:11:55 AM »
Hi,

 I have now put this action on the Ecosystem

Thanks :)

 Jean