rereplace help
-
I’m trying to automate some of my coding tasks using pythonscript and running into an issue I think regex should be able to solve. I want to replace things that are specifically surrounded by certain characters while preserving the middle part.
so for example:
" & Placeholder &"
becomes:
{Placeholder}
I thought that named capture variables would be able to do this but I am getting an empty {} trying to use them in this situation with the code:
editor.rereplace(r" & \b(?<Placeholder_Variable>[a-zA-Z0-9._]*)\b & “,r”{(?{Placeholder_Variable})}")
-
You have several things wrong in your regular expression.
Try this instead:
editor.rereplace(r'" & (?<Placeholder_Variable>\w+) &"', r'{$+{Placeholder_Variable}}')EDIT: Oops, the first version of this posting used Python named capture group stuff; I’ve adjusted to use Boost equivalents.
-
@Alan-Kilborn I had to re-add ‘.*’ to the middle section, but I got it working now and can use variables the way I want now, thanks!!
Hello! It looks like you're interested in this conversation, but you don't have an account yet.
Getting fed up of having to scroll through the same posts each visit? When you register for an account, you'll always come back to exactly where you were before, and choose to be notified of new replies (either via email, or push notification). You'll also be able to save bookmarks and upvote posts to show your appreciation to other community members.
With your input, this post could be even better 💗
Register Login