Search and Delete

General questions about using TextPad

Moderators: AmigoJack, bbadmin, helios, Bob Hansen, MudGuard

Post Reply
hjack
Posts: 26
Joined: Mon Apr 17, 2006 3:06 am
Location: Kentucky

Search and Delete

Post 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
ak47wong
Posts: 703
Joined: Tue Aug 12, 2003 9:37 am
Location: Sydney, Australia

Post 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
hjack
Posts: 26
Joined: Mon Apr 17, 2006 3:06 am
Location: Kentucky

Search and delete

Post by hjack »

Thanks, Andrew. So simple when you talk to experts.
hjack
Posts: 26
Joined: Mon Apr 17, 2006 3:06 am
Location: Kentucky

search and delete

Post 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
ben_josephs
Posts: 2464
Joined: Sun Mar 02, 2003 9:22 pm

Post by ben_josephs »

It's all in the previous answer.
Find what: <checkbox element=.* label
Replace with: <checkbox label

[X] Regular expression

Replace All
hjack
Posts: 26
Joined: Mon Apr 17, 2006 3:06 am
Location: Kentucky

search and delete

Post 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
ben_josephs
Posts: 2464
Joined: Sun Mar 02, 2003 9:22 pm

Post 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
hjack
Posts: 26
Joined: Mon Apr 17, 2006 3:06 am
Location: Kentucky

search and replace

Post 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
ben_josephs
Posts: 2464
Joined: Sun Mar 02, 2003 9:22 pm

Post 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?
hjack
Posts: 26
Joined: Mon Apr 17, 2006 3:06 am
Location: Kentucky

search and delete

Post 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
ben_josephs
Posts: 2464
Joined: Sun Mar 02, 2003 9:22 pm

Post 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
hjack
Posts: 26
Joined: Mon Apr 17, 2006 3:06 am
Location: Kentucky

search and delete

Post 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.
Post Reply