I’m using Version: 6.4.6.2
Build ID: 1:6.4.6-0ubuntu0.20.04.1
I need to find & replace strings in a document that have a new line.
I’m using document.getText().String
to get the text for the document then doing a regex for signature lines using the pattern: r"(____[\_]+)\n([A-z0-9\-]+)\s+([A-z0-9\ \-]+)\n"
It finds lines like this:
__________ First Last
The end goal is to have it replace with something like:
First_____ First Last
# Failed replace = document.createReplaceDescriptor() replace.SearchRegularExpression = True replace.SearchString = r"____\nFirst" replace.ReplaceString = r"WORKS____\nWORKS" document.replaceAll(replace) # Failed replace = document.createReplaceDescriptor() replace.SearchRegularExpression = True replace.SearchString = r"____\\nFirst" replace.ReplaceString = r"nWORKS____\\nWORKS" document.replaceAll(replace) # Failed replace = document.createReplaceDescriptor() replace.SearchRegularExpression = False replace.SearchString = r"____\nFirst" replace.ReplaceString = r"Works____\nFirst" document.replaceAll(replace) # Failed replace = document.createReplaceDescriptor() replace.SearchRegularExpression = False replace.SearchString = r"____\nFirst" replace.ReplaceString = r"Works____\nFirst" document.replaceAll(replace)
I found this post Find character and replace with a new line but I don’t know how to access the dialog, and on top of that doesn’t find (____[\_]+)\nFirst
or ____[\_]+\nFirst