Replace string - n occurences

Can the replace string expression function (for property binding) be configured to replace n occurences of a substring than a replaceall

A Quick glance at the documentation leads me to believe that the expression does not allow for anything other than “replace each occurrence of ‘some_value’ with ‘some_other_value’”.

There are always other avenues to accomplish what you’re looking to do. have you tried using runScript ? You could supply your own function to perform the ‘n-occurences’ logic as applied to a supplied string argument.

runScript(project.myScript.replaceFirstNOccurences, args={'my_str': "banana", 'replace_this_text': "a", 'with_this': "i", 'n_occur': 2})

Project script:

def replaceFirstNOccurences(my_str, replace_this_text, with_this, n_occur):
    return str(my_str).replace(replace_this_text, with_this, n_occur)

The provided expression/script combo should return “binina”.