Page 1 of 1
Search and Delete
Posted: Tue May 05, 2009 4:06 am
by hjack
I have a series of lines, each containing different words, which I want to delete. Example:
<start>john doe</start>
<start>Fred Jones</start>
<start>David Sylvester Smith</start>
Can someone please help a rookie understand how I can replace all of the above names, leaving the following:
<start></start>
<start></start>
<start></start>
Thanks
Jack
Posted: Tue May 05, 2009 5:41 am
by ak47wong
You can perform a replace operation with the following values:
Find what: <start>.*</start>
Replace with: <start></start>
[x] Regular expression
The expression ".*" represents any sequence of any characters.
Andrew
Search and delete
Posted: Tue May 05, 2009 1:29 pm
by hjack
Thanks, Andrew. So simple when you talk to experts.
search and delete
Posted: Tue May 05, 2009 6:09 pm
by hjack
Andrew, or others, another 'simple' problem.
In my xml app, I need to change the following:
<checkbox element="cc;john doe" label
<checkbox element="cc;bill adams" label
<checkbox element="cc;ron howard" label
to
<checkbox label
<checkbox label
<checkbox label
Can you help me with this?
Thanks
Jack
Posted: Tue May 05, 2009 6:37 pm
by ben_josephs
It's all in the previous answer.
Find what: <checkbox element=.* label
Replace with: <checkbox label
[X] Regular expression
Replace All
search and delete
Posted: Tue May 05, 2009 7:26 pm
by hjack
Ben, this works for most of the elements, but there is another problem.
<checkbox element="cc;john Doe" id-type"xx" label
<checkbox element="fred jones " id-type"xx" label
I want to replace the characters and quotations in the first example leaving the id-type"xx" label. As you suggested, .* replaces all characters to label (which works in my original problem, but deletes id-type="xx")
In the second example, there is no cc; and therefore I want this particular element to be ignored.
Probably clear as mud. In essence, if the element complex contains the cc; I want to delete element="cc;xxxx" to the id-type"xx" label. If there is no cc; I want it to be left alone.
Again, your help, knowledge, and time are very much appreciated.
Jack
Posted: Tue May 05, 2009 8:24 pm
by ben_josephs
Something like this should do it, for lines with or without the
id-type bit, but only if there's a
"cc;..." bit:
Find what: <checkbox element="cc;[^"]*" ((id-type".*" )?label)
Replace with: <checkbox \1
[X] Regular expression
Replace All
This assumes you are using Posix regular expression syntax:
Configure | Preferences | Editor
[X] Use POSIX regular expression syntax
search and replace
Posted: Tue May 05, 2009 9:06 pm
by hjack
Thanks, Ben. This works on most lines, but I have now found several lines as below:
<checkbox element="cc;xxx" id="xxxxx xx" id-type="xx" label
<checkbox element="cc;xxx" id-type="xx" id="xxxx xxx xx" label
I am unclear how to modify your expression to delete these extra id's.
Thanks
Jack
Posted: Tue May 05, 2009 10:23 pm
by ben_josephs
Would it be easiest just to delete the
id attributes?
Find what: id="[^"]*" (with a space at the end)
Replace with: [nothing]
[X] Regular expression
Replace All
or does that catch some you don't want to delete?
search and delete
Posted: Tue May 05, 2009 11:21 pm
by hjack
As usual, Ben, you are very perceptive. That is just what I am trying to avoid. Here is a typical series in my app:
<checkbox element="cc;xxx" id="xxx xxx" id-type="x" label
<checkbox element="xxx;xx" id="xxx xxxx xxx xx" id-type="x" label
<checkbox element="xxx;xx" id="xx xxxx xx xxx" id-type="x" label
<checkbox element="xxx;xx" id-type="x" id="xxx xxxx xxx xx" label
<checkbox element="cc;xxxx" id-type="x" id="xxxxx xx" label
I want to delete the 'element="cc"xxx" in line 1, leave lines 2,3,and 4 intact, and delete the 'element=cc;xxxx" in line 5. Note that in some lines, the id-type and id= are reversed in order. In my apps, all id's and id types must stay intact. This result is ultimately what I am trying to achieve:
<checkbox id="xxx xxx" id-type="x" label
<checkbox element="xxx;xx" id="xxx xxxx xxx xx" id-type="x" label
<checkbox element="xxx;xx" id="xx xxxx xx xxx" id-type="x" label
<checkbox element="xxx;xx" id-type="x" id="xxx xxxx xxx xx" label
<checkbox id-type="x" id="xxxxx xx" label
Again, thanks. I have over 350 occurrences of the cc; in each of 5 different apps, so this would be a major assistance to me.
Jack
Posted: Wed May 06, 2009 5:55 am
by ben_josephs
Before you wrote that you want "to delete these extra id's". Now you write "all id's and id types must stay intact". Assuming the latter:
Find what: <checkbox element="cc;[^"]*"
Replace with: <checkbox
search and delete
Posted: Wed May 06, 2009 10:27 pm
by hjack
Ben, sorry about any ambiguity. This works fine. I do sincerely appreciate your help, as it has saved me about 5 hours of work and frustration.