I have the following text.
... (More lines with similar format)
commandRef ENCBOMEditAll 2' has been deleted.
commandRef ENCBOMCopyFrom 3' has been deleted.
commandRef AEFSeparator 4' has been deleted.
... (More lines with similar format)
commandRef ENCEBOMTableEditAll 3' has been added.
commandRef ENCBOMCopyFrom 4' has been added.
commandRef AEFSeparator 5' has been added.
... (More lines with similar format)
I want to remove the "deleted-added" pair in the text. For example, I want to remove: (The number in the line is their order which I dont care)
commandRef ENCBOMCopyFrom 3' has been deleted.
commandRef ENCBOMCopyFrom 4' has been added.
How can I do that with regex replace?
Thanks,
RegEx replace
Moderators: AmigoJack, bbadmin, helios, Bob Hansen, MudGuard
I can find the "deleted" line and "added" line.
I real problem is, how to represent the multiple lines between these 2 lines?
Code: Select all
commandRef \(.*\) [0-9]*' has been deleted.\n
<what should be here?>
commandRef \1 [0-9]*' has been added.\n
- Bob Hansen
- Posts: 1516
- Joined: Sun Mar 02, 2003 8:15 pm
- Location: Salem, NH
- Contact:
Don't have a complete solution yet, but here is an overview approach that allows a manual delete process for lines with matching numbers:
1. Reformat the lines so the numbers are at the front of the line.
2. Sort the lines by the first 10 chars to combine the matching numbers.
3. Remove the duplicate lines where the first 1o chars are duplicated.
4. Reformat the lines to original format
Start with:
commandRef ENCBOMEditAll 2' has been deleted.
commandRef ENCBOMCopyFrom 3' has been deleted.
commandRef AEFSeparator 4' has been deleted.
commandRef ENCEBOMTableEditAll 3' has been added.
commandRef ENCBOMCopyFrom 4' has been added.
commandRef AEFSeparator 5' has been added.
Step 1:
Search for: ^(.*)([0-9]+' has.*\.)
Replace with: \2\1
Result:
2' has been deleted.commandRef ENCBOMEditAll
3' has been deleted.commandRef ENCBOMCopyFrom
4' has been deleted.commandRef AEFSeparator
3' has been added.commandRef ENCEBOMTableEditAll
4' has been added.commandRef ENCBOMCopyFrom
5' has been added.commandRef AEFSeparator
Step 2:
Tools/Sort/
From 1, Length 10
Ascending.
Result:
2' has been deleted.commandRef ENCBOMEditAll
3' has been added.commandRef ENCEBOMTableEditAll
3' has been deleted.commandRef ENCBOMCopyFrom
4' has been added.commandRef ENCBOMCopyFrom
4' has been deleted.commandRef AEFSeparator
5' has been added.commandRef AEFSeparator
Step3:
Can delete matching number lines manually now, but need a solution to do automatically\
Result:
2' has been deleted.commandRef ENCBOMEditAll
5' has been added.commandRef AEFSeparator
Step:
Search for: ^(.*d\.)(.*)
Replace with: \2\1
Result:
commandRef ENCBOMEditAll 2' has been deleted.
commandRef AEFSeparator 5' has been added.
1. Reformat the lines so the numbers are at the front of the line.
2. Sort the lines by the first 10 chars to combine the matching numbers.
3. Remove the duplicate lines where the first 1o chars are duplicated.
4. Reformat the lines to original format
Start with:
commandRef ENCBOMEditAll 2' has been deleted.
commandRef ENCBOMCopyFrom 3' has been deleted.
commandRef AEFSeparator 4' has been deleted.
commandRef ENCEBOMTableEditAll 3' has been added.
commandRef ENCBOMCopyFrom 4' has been added.
commandRef AEFSeparator 5' has been added.
Step 1:
Search for: ^(.*)([0-9]+' has.*\.)
Replace with: \2\1
Result:
2' has been deleted.commandRef ENCBOMEditAll
3' has been deleted.commandRef ENCBOMCopyFrom
4' has been deleted.commandRef AEFSeparator
3' has been added.commandRef ENCEBOMTableEditAll
4' has been added.commandRef ENCBOMCopyFrom
5' has been added.commandRef AEFSeparator
Step 2:
Tools/Sort/
From 1, Length 10
Ascending.
Result:
2' has been deleted.commandRef ENCBOMEditAll
3' has been added.commandRef ENCEBOMTableEditAll
3' has been deleted.commandRef ENCBOMCopyFrom
4' has been added.commandRef ENCBOMCopyFrom
4' has been deleted.commandRef AEFSeparator
5' has been added.commandRef AEFSeparator
Step3:
Can delete matching number lines manually now, but need a solution to do automatically\
Result:
2' has been deleted.commandRef ENCBOMEditAll
5' has been added.commandRef AEFSeparator
Step:
Search for: ^(.*d\.)(.*)
Replace with: \2\1
Result:
commandRef ENCBOMEditAll 2' has been deleted.
commandRef AEFSeparator 5' has been added.
Last edited by Bob Hansen on Thu Oct 23, 2008 10:39 pm, edited 1 time in total.
Hope this was helpful.............good luck,
Bob
Bob
need a solution to do automatically
Thanks Bob, but I need a automatic solution, not delete manually. If I would do it manually, I will just highlight those lines, sort, and delete manually.
There are more other lines in the text, like
Thanks,
There are more other lines in the text, like
I am looking for a way to represent multiple lines between 2 regex, as I mentioned in my second note.<Beginning text>
...
====== 'menu' 'APPRouteContentActionsToolBar' ======
commandRef APPRouteContentUploadExternalFile 2' has been deleted.
menuRef APPRouteContentSummaryCreateNew 2' has been added.
====== 'menu' 'APPDiscussionDocumentSummaryActionsToolBar' ======
commandRef APPDocumentCreateNew 1' has been deleted.
menuRef APPContentSummaryCreateNew 1' has been added.
====== 'menu' 'APPFileSummaryActionsToolBar' ======
commandRef APPSeparator 3' has been deleted.
commandRef APPCommonDocumentDownloadActionLink 4' has been deleted.
commandRef APPCommonDocumentCheckOutActionLink 5' has been deleted.
commandRef APPVersionDelete 6' has been deleted.
commandRef APPFileDelete 7' has been deleted.
commandRef APPCDMTOVCConversionFilesActionConnect 3' has been added.
commandRef APPCDMTOVCConversionFilesActionCheckIn 4' has been added.
commandRef APPCDMTOVCConversionFilesActionCopy 5' has been added.
commandRef APPSeparator 6' has been added.
commandRef APPCommonDocumentDownloadActionLink 7' has been added.
commandRef APPCommonDocumentCheckOutActionLink 8' has been added.
commandRef APPVersionDelete 9' has been added.
commandRef APPFileDelete 10' has been added.
...
<Ending text>
Thanks,
-
- Posts: 2461
- Joined: Sun Mar 02, 2003 9:22 pm
This sort of thing has been discussed many times before. There is no way to automate it fully in TextPad.
Unfortunately, TextPad's aged regex engine is incapable of matching text containing an arbitrary number of newlines. Also, back-references such as \1 in TextPad's regexes can't refer back over a newline. That is, you can't have a newline between a captured subexpression and a reference back to it.
I don't believe that reordering the lines as Bob suggests will work in this case. I understand from "The number in the line is their order which I dont care" that it's the numbers you don't care about; I presume that you want the lines left in their original order. You could insert line numbers at the beginnings of the lines, sort the lines by the text after commandRef, do something very tricky (I'm not sure what, but it would involve removing and restoring newlines), sort the lines by the line numbers you added earlier, and remove those line numbers. But this would be absurdly complicated.
Alternatively, you could try WildEdit (http://www.textpad.com/products/wildedit/), which uses a far more powerful regex engine.
I would be far easier to do this with a script. TextPad doesn't support scripts, so you would have to use a suitable scripting language, such as Perl, Python, Ruby or Tcl.
Unfortunately, TextPad's aged regex engine is incapable of matching text containing an arbitrary number of newlines. Also, back-references such as \1 in TextPad's regexes can't refer back over a newline. That is, you can't have a newline between a captured subexpression and a reference back to it.
I don't believe that reordering the lines as Bob suggests will work in this case. I understand from "The number in the line is their order which I dont care" that it's the numbers you don't care about; I presume that you want the lines left in their original order. You could insert line numbers at the beginnings of the lines, sort the lines by the text after commandRef, do something very tricky (I'm not sure what, but it would involve removing and restoring newlines), sort the lines by the line numbers you added earlier, and remove those line numbers. But this would be absurdly complicated.
Alternatively, you could try WildEdit (http://www.textpad.com/products/wildedit/), which uses a far more powerful regex engine.
I would be far easier to do this with a script. TextPad doesn't support scripts, so you would have to use a suitable scripting language, such as Perl, Python, Ruby or Tcl.
I got it worked by myself
Hi Ben,
Your notes reminded me to put all commandRef/menuRef in one single line, and I got it worked.
First, remove \n between commandRef/menuRef.
Then, remove "deleted-added" pair.
Last, add \n back.
Thanks for the help.
Your notes reminded me to put all commandRef/menuRef in one single line, and I got it worked.
First, remove \n between commandRef/menuRef.
Code: Select all
replace:
\([commandmenu]*\)Ref\(.*\)\n\([commandmenu]*\)Ref
with:
\1Ref\2\3Ref
Code: Select all
replace:
\([commandmenu]*\)Ref \([[:alnum:]_]*\) [0-9]*' has been deleted.\(.*\)\1Ref \2 [0-9]*' has been added.
with
\3
Code: Select all
replace:
\([commandmenu]*\)Ref\(.*\)\.\([commandmenu]*\)Ref
with
\1Ref\2\.\n\3Ref
-
- Posts: 2461
- Joined: Sun Mar 02, 2003 9:22 pm
Ah, I see. I slighthly misunderstood your problem.
You will help yourself by using Posix syntax:
\([commandmenu]*\)Ref\(.*\)\n\([commandmenu]*\)Ref
becomes
([commandmenu]*)Ref(.*)\n([commandmenu]*)Ref
which is somewhat clearer.
But
[commandmenu]*
is incorrect. It means: any number (possibly zero) of the characters c, o, m, m, a, n, d, m, e, n or u (that is, the characters c, o, m, a, n, d, e or u). I think you mean
command|menu
which means either command or menu.
So the whole becomes
(command|menu)Ref(.*)\n(command|menu)Ref
You will help yourself by using Posix syntax:
Then, for example, your regexConfigure | Preferences | Editor
[X] Use POSIX regular expression syntax
\([commandmenu]*\)Ref\(.*\)\n\([commandmenu]*\)Ref
becomes
([commandmenu]*)Ref(.*)\n([commandmenu]*)Ref
which is somewhat clearer.
But
[commandmenu]*
is incorrect. It means: any number (possibly zero) of the characters c, o, m, m, a, n, d, m, e, n or u (that is, the characters c, o, m, a, n, d, e or u). I think you mean
command|menu
which means either command or menu.
So the whole becomes
(command|menu)Ref(.*)\n(command|menu)Ref