regexexpressionregular-language

Need simple regex (regular expression) for dynamic expression


I need a regex to replace this text:

("{scriptid}_*0123_00000000_ABC-Description*");

With this text:

("{scriptid}_*0123_00000000_ABC-Description*"));

Or in other words: *I have to add a second closing brace.

Explanation:

("{scriptid}_*0123_00000000_ABC-Description*");

("{scriptid}_4-digits_8-alphanumeric_X-alphanumeric-description");

I tried some expressions but it doesn't really work.

Could some one please help me?


Solution

  • A generic regex that matches all the lines ending with ');' (match also if there are trailing spaces) can be this:

    s/\);\s*$/\)\);/
    

    Test online here.

    UPDATE: generic regex that adds a closing parenthesis, matches only lines starting with lr_start_transaction:

    s/^\s*(lr_start_transaction.*\))\s*;\s*$/\1\);/
    

    Test online here.

    Anyway, if we are not talking about generic regex you have to also specify the language you are coding with (cause each regex engine is thinly different).

    Consider also to include some lines that does not have to match.