<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Assign Regular Expression to variable in FlexSim Forum</title>
    <link>https://forums.autodesk.com/t5/flexsim-forum/assign-regular-expression-to-variable/m-p/13520141#M31232</link>
    <description>&lt;DIV class="fr-view clearfix"&gt;&lt;P&gt;&lt;A rel="user" href="https://answers.flexsim.com/users/6258/jeremyr.html"&gt;@jeremy.r&lt;/A&gt;&lt;/P&gt;&lt;P&gt;You can wrap the syntax of that example into a user command so that your usage of it is cleaner:&lt;/P&gt;&lt;PRE&gt;return stringReplaceRegEx("blue cars are really green.", "/blue/gi", "red");&lt;/PRE&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper" image-alt="32407-regex-usercommand.png"&gt;&lt;img src="https://forums.autodesk.com/t5/image/serverpage/image-id/1503541i92814EB8F1289D9F/image-size/large?v=v2&amp;amp;px=999" role="button" title="32407-regex-usercommand.png" alt="32407-regex-usercommand.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&lt;A rel="noopener noreferrer" href="https://answers.flexsim.com/storage/temp/32404-regex-usercommand.fsm" target="_blank"&gt;regex_usercommand.fsm&lt;/A&gt;&lt;/P&gt;&lt;/DIV&gt;</description>
    <pubDate>Tue, 08 Sep 2020 16:12:17 GMT</pubDate>
    <dc:creator>philboboADSK</dc:creator>
    <dc:date>2020-09-08T16:12:17Z</dc:date>
    <item>
      <title>Assign Regular Expression to variable</title>
      <link>https://forums.autodesk.com/t5/flexsim-forum/assign-regular-expression-to-variable/m-p/13520138#M31229</link>
      <description>&lt;P&gt;&lt;I&gt;[ FlexSim 18.2.3 ]&lt;/I&gt;&lt;/P&gt;&lt;DIV class="fr-view clearfix"&gt;&lt;P&gt;Functions like string.match() and string.replace() can use regular expressions. According to the documentation, regular expressions are actually of the RegExp type. However, RegExp doesn't appear to be a valid type for a variable. i.e. the following code does not work&lt;/P&gt;&lt;PRE&gt;RegExp expression = /[0-9]/;&lt;/PRE&gt;&lt;P&gt;Is there any way to assign a regular expression to a variable? Or are all regular expressions required to be defined directly in the code?&lt;/P&gt;&lt;P&gt;The key reason I wanted to do this was to be able to dynamically construct a regular expression in code. Is there any way to do that in FlexScipt (e.g. constructing a string, then converting that string to a regular expression)?&lt;/P&gt;&lt;/DIV&gt;</description>
      <pubDate>Fri, 04 Sep 2020 07:25:56 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/flexsim-forum/assign-regular-expression-to-variable/m-p/13520138#M31229</guid>
      <dc:creator>jeremy_r</dc:creator>
      <dc:date>2020-09-04T07:25:56Z</dc:date>
    </item>
    <item>
      <title>Re: Assign Regular Expression to variable</title>
      <link>https://forums.autodesk.com/t5/flexsim-forum/assign-regular-expression-to-variable/m-p/13520139#M31230</link>
      <description>&lt;DIV class="fr-view clearfix"&gt;&lt;P&gt;You cannot dynamically construct a regular expression in FlexScript currently.&lt;/P&gt;&lt;P&gt;They can only be used as literals directly in the code where you are using them.&lt;/P&gt;&lt;P&gt;You cannot store them in a variable, return them from a function, or construct them from a string.&lt;/P&gt;&lt;P&gt;EDIT: If you build up the entire function call, then you can use executestring() to execute it. You can't execute just the regex part though, because you can't return a regex from a function. You must execute the entire function:&lt;/P&gt;&lt;PRE&gt;string text = "blue cars are really green.";
string findPattern = "/blue/gi";
if (uniform(0, 1) &amp;gt; 0.5)
&amp;nbsp; &amp;nbsp;&amp;nbsp;findPattern = "/green/gi";
string replaceWith = "red";

var function_with_regex = "eventdata.as(string).replace(" + findPattern + ", \"" + replaceWith + "\")";
return executestring(function_with_regex, 0, 0, text);&lt;/PRE&gt;&lt;/DIV&gt;</description>
      <pubDate>Fri, 04 Sep 2020 15:33:14 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/flexsim-forum/assign-regular-expression-to-variable/m-p/13520139#M31230</guid>
      <dc:creator>philboboADSK</dc:creator>
      <dc:date>2020-09-04T15:33:14Z</dc:date>
    </item>
    <item>
      <title>Re: Assign Regular Expression to variable</title>
      <link>https://forums.autodesk.com/t5/flexsim-forum/assign-regular-expression-to-variable/m-p/13520140#M31231</link>
      <description>&lt;DIV class="fr-view clearfix"&gt;&lt;P&gt;Alright, that's disappointing, but pretty much what I expected. Thanks for the direct answer.&lt;/P&gt;&lt;/DIV&gt;</description>
      <pubDate>Sun, 06 Sep 2020 23:14:51 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/flexsim-forum/assign-regular-expression-to-variable/m-p/13520140#M31231</guid>
      <dc:creator>jeremy_r</dc:creator>
      <dc:date>2020-09-06T23:14:51Z</dc:date>
    </item>
    <item>
      <title>Re: Assign Regular Expression to variable</title>
      <link>https://forums.autodesk.com/t5/flexsim-forum/assign-regular-expression-to-variable/m-p/13520141#M31232</link>
      <description>&lt;DIV class="fr-view clearfix"&gt;&lt;P&gt;&lt;A rel="user" href="https://answers.flexsim.com/users/6258/jeremyr.html"&gt;@jeremy.r&lt;/A&gt;&lt;/P&gt;&lt;P&gt;You can wrap the syntax of that example into a user command so that your usage of it is cleaner:&lt;/P&gt;&lt;PRE&gt;return stringReplaceRegEx("blue cars are really green.", "/blue/gi", "red");&lt;/PRE&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper" image-alt="32407-regex-usercommand.png"&gt;&lt;img src="https://forums.autodesk.com/t5/image/serverpage/image-id/1503541i92814EB8F1289D9F/image-size/large?v=v2&amp;amp;px=999" role="button" title="32407-regex-usercommand.png" alt="32407-regex-usercommand.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&lt;A rel="noopener noreferrer" href="https://answers.flexsim.com/storage/temp/32404-regex-usercommand.fsm" target="_blank"&gt;regex_usercommand.fsm&lt;/A&gt;&lt;/P&gt;&lt;/DIV&gt;</description>
      <pubDate>Tue, 08 Sep 2020 16:12:17 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/flexsim-forum/assign-regular-expression-to-variable/m-p/13520141#M31232</guid>
      <dc:creator>philboboADSK</dc:creator>
      <dc:date>2020-09-08T16:12:17Z</dc:date>
    </item>
  </channel>
</rss>

