Search code examples
regexhaxeflashdevelop

How to rearrange code using Regular Expressions in HaxeDevelop / FlashDevelop Find and Replace


I'm trying to turn cast(("Sparkles"), GetBitmapData); to GetBitmapData("Sparkles");

I've got this for my find code:

cast\(\(\"\.*\"\),\ .*\);

but this replace doesn't work:

$2\(\"$1\"\);

What do I need to do to make this work?


Solution

  • You regex does not contain capturing groups and you try to access them with numbered backreferences. Besides, you escaped the dot, and \.* just matches 0+ dot symbols.

    You may use the following regex replacement:

    Find what:       cast\(\("(.*?)"\),\s*(\w+)\);
    Replace with: $2("$1");

    Here is a .NET regex demo (FlashDevelop S&R feature uses .NET regex flavor).

    Pattern details:

    • cast\(\(" - a cast((" substring
    • (.*?) - Group 1 (referred to with $1) capturing any 0+ chars as few as possible up to the first...
    • "\), - a "), substring
    • \s* - 0+ whitespaces
    • (\w+) - Group 2 (referred to with $2) capturing 1+ word chars (letters/digits/_)
    • \); - a ); substring.