Another regex in action script

hi, have some issues here with regex. Can anyone help?

this works in FixletDebugger:

q: exists match (regex “^([A-Za-z0-9]{4}-){5}[A-Za-z0-9]{4}$”) of (“aaaa-1aaa-1aaa-aaaa-a1aa-aaaa”)
A: True
T: 0.032 ms

but it fails in action script. I assumed it would need to escape the curly braces, but that didn’t change anything:

Failed continue if {exists match (regex "^([A-Za-z0-9]{{4}-){{5}[A-Za-z0-9]{{4}$") of (parameter "key" of action as string)}

I’m guessing there is still some sort of problem with the { and how they are escaped in your actionscript.

I’d propose not using RegEx, even if it doesn’t do the same level of checking.

Relevance:

6 = number of substrings separated by "-" whose(length of it = 4) of "aaaa-1aaa-1aaa-aaaa-a1aa-aaaa"

ActionScript:

continue if { 6 = number of substrings separated by "-" whose(length of it = 4) of "aaaa-1aaa-1aaa-aaaa-a1aa-aaaa" }

When you do not want to begin a Relevance Substitution, you need to escape the open curly brackets via {{. When you don’t want to end a relevance substitution, you need to escape the close curly brackets via }}. Try

continue if {exists match (regex "^([A-Za-z0-9]{4}}-){5}}[A-Za-z0-9]{4}}$") of (parameter "key" of action as string)}```
2 Likes

i tried escaping the end curly brackets, but that still failed…

continue if {exists match (regex "^([A-Za-z0-9]{4}}-){5}}[A-Za-z0-9]{4}}$") of (parameter "key" of action as string)}

however, changing the curly brackets to their hex values worked ( “{”="%7B" & “}”="%7D"

continue if {exists match (regex "^([A-Za-z0-9]%7B4%7D-)%7B5%7D[A-Za-z0-9]%7B4%7D$") of (parameter "key" of action as string)}

Escaping them with the %hex is often the way to go because it usually works.

If escaping just the end brackets doesn’t work, try escaping just the beginning ones and see if that does it.

both failed in 2 different test. 1) escaping the { with %7B, and 2) escaping the } with %7D.

Oh well, it works for me replacing { } with %7B %7D.

I have an example here: https://bigfix.me/fixlet/details/6189?force=true of escaping brackets that were used in a regex string (Though mine was using powershell and not action script):

parameter “VerRegEx”=“href=”"(/repository/.{{0,10}/(.{{0,10})/.{{0,20}Installer.exe)"

I just had to escape the opening bracket

Edit
see @JasonWalker’s reply for why this is wrong

1 Like

I meant escaping the opening { by making it {{ and not escaping the ending one at all, keep it as }

That’s a different case:

– Here, you are trying to prevent a Relevance Substitution; you want ActionScript to treat the { as “not the beginning of Relevance”

– Here, you are inside a Relevance substitution; and you want to treat } as “not the end of Relevance”

How we actually accomplish it is open for explanation. I’m pretty positive that using “}}” has worked for me but I don’t have a console at home to try. I just want to point out that we are talking about two different use cases. It looks like %7B and %7D may be a good method in any case.

2 Likes

I agree, using % to escape them usually works, without needing to figure out which you need to escape.