Really simply: new RegExp(“?”) In Flash, that will produce a RegExp object which matches nothing.
In JS, it throws an error that the RegExp is not valid. match and search seem to call the RegExp constructor under the hood. In Flash it succeeds. In JS it throws an error. Utility functions serve two purposes: 1. It prevents the error from being thrown. 2. It warns the developer to not pass in a string as it’s converted to a RegExp anyway and is less predictable. An alternate (possibly better) way to handle this would be to have the compiler issue a warning. > On Jul 20, 2017, at 7:05 PM, Alex Harui <aha...@adobe.com.INVALID> wrote: > > I think I'm lost. If both behave the same, then why do we need to call > some utility function? > > -Alex > > On 7/20/17, 5:00 AM, "Yishay Weiss" <yishayj...@hotmail.com> wrote: > >> Good catch. I was misled by the docs [1]. >> >> [1] >> https://na01.safelinks.protection.outlook.com/?url=http%3A%2F%2Fhelp.adobe >> .com%2Fen_US%2FFlashPlatform%2Freference%2Factionscript%2F3%2FString.html% >> 23match&data=02%7C01%7C%7C66b63f8228ab4f80a39408d4cf66f9a9%7Cfa7b1b5a7b344 >> 38794aed2c178decee1%7C0%7C0%7C636361488561328745&sdata=CbWB8sk4vOv1vId9aT7 >> WkDjQrkqarHU2aAAoWw9UBNA%3D&reserved=0() >> >> From: Harbs<mailto:harbs.li...@gmail.com> >> Sent: Thursday, July 20, 2017 9:40 AM >> To: dev@flex.apache.org<mailto:dev@flex.apache.org> >> Subject: Re: [FlexJS] String.match() >> >> Both Flash and JS engines automatically convert to RegExp. I had not >> realized that at first. >> >> It seems that the only difference between the Flash engine and JS engines >> is what happens when constructing a RegExp object from invalid input. >> Flash matches nothing, while JS throws an error. >> >> By just wrapping the call in a try/catch, that seems to resolve the issue. >> >> I added the trace because I think it’s bad practice to use strings >> instead of RegExp because it can lead to unexpected results and a new >> RegExp instance needs to be constructed every time. >> >>> On Jul 20, 2017, at 3:32 AM, Alex Harui <aha...@adobe.com.INVALID> >>> wrote: >>> >>> It looks like they just trace a warning instead of trying to convert to >>> a >>> RegExp. Is that what we want to do? Or should we add code that >>> converts >>> a string to regex? >>> >>> Thoughts? >>> -Alex >>> >>> On 7/19/17, 4:32 AM, "Harbs" <harbs.li...@gmail.com> wrote: >>> >>>> I added the utility functions. I think they can be very simple. >>>> >>>>> On Jul 19, 2017, at 9:30 AM, Alex Harui <aha...@adobe.com.INVALID> >>>>> wrote: >>>>> >>>>> Unless we are absolutely sure that everybody will need the code >>>>> generated >>>>> by the compiler, having the compiler call a framework function makes >>>>> it >>>>> easier for an app developer to make any adjustments to that code. It >>>>> is >>>>> easier to monkey-patch a utility function than find-and-replace some >>>>> sequence of code the compiler has sprinkled throughout the output. >>>>> >>>>> My 2 cents, >>>>> -Alex >>>>> >>>>> On 7/18/17, 11:36 AM, "yishayw" <yishayj...@hotmail.com> wrote: >>>>> >>>>>> Alex Harui-2 wrote >>>>>>> By >>>>>>> calling new utility functions, the developer has control over the >>>>>>> conversion. >>>>>> >>>>>> I don't understand that point. Do you mean an app developer? >>>>>> >>>>>> >>>>>> >>>>>> >>>>>> -- >>>>>> View this message in context: >>>>>> >>>>>> >>>>>> https://na01.safelinks.protection.outlook.com/?url=http%3A%2F%2Fapache >>>>>> -f >>>>>> le >>>>>> >>>>>> >>>>>> x-development.2333347.n4.nabble.com%2FFlexJS-String-match-tp63392p6340 >>>>>> 5. >>>>>> ht >>>>>> >>>>>> >>>>>> ml&data=02%7C01%7C%7C9ff1088402ef439ca27908d4ce0e97eb%7Cfa7b1b5a7b3443 >>>>>> 87 >>>>>> 94 >>>>>> >>>>>> >>>>>> aed2c178decee1%7C0%7C0%7C636360009448210304&sdata=nprl9yHUtlsTHbIZxeFq >>>>>> 2h >>>>>> %2 >>>>>> FQNWmtimM%2BxAt0kJA8EcA%3D&reserved=0 >>>>>> Sent from the Apache Flex Development mailing list archive at >>>>>> Nabble.com. >>>>> >>>> >>> >> >