using wildcard with Replace command

General questions about using TextPad

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

Post Reply
CitznFish
Posts: 2
Joined: Wed May 21, 2003 5:18 pm

using wildcard with Replace command

Post by CitznFish »

I searched through the forums but haven't really found an answer to this. I would have thought this was a question often asked.

Is there any way to use wildcards when using the replace command?

For example, I have a list of 2000 items as shown below. I want to remove the [filename].html from each line in the list. using * as a wildcard doesn't work. Is there a way to do this?

/entertain/books/feature/aakd118books/aakd118books.html
/travel/places/feature/aakd199703_terrific/aakd199703_terrific.html
/travel/places/feature/aakd29getaway/aakd29getaway.html


should end up like this:

/entertain/books/feature/aakd118books/
/travel/places/feature/aakd199703_terrific/
/travel/places/feature/aakd29getaway/


also would there be a way to remove duplicate lines such as:

/entertain/books/feature/aakd118books/
/travel/places/feature/aakd199703_terrific/
/travel/places/feature/aakd29getaway/
/travel/places/feature/aakd29getaway/
/travel/places/feature/aakd29getaway/



I know nothing about PERL (the only close answer I found searching the forums)

Thank you!
Ed
Posts: 103
Joined: Tue Mar 04, 2003 9:09 am
Location: Devon, UK

Post by Ed »

What you need is a Regular Expression.

Find
^\(.*\)/[^/]+\.html *$
Replace with
\1/

make sure "Regular Expression" box is ticked

F9 will sort your file and there is an option to delete duplicates
User avatar
Bob Hansen
Posts: 1517
Joined: Sun Mar 02, 2003 8:15 pm
Location: Salem, NH
Contact:

Post by Bob Hansen »

For a wild card you will have to use a Regex looking for:
/ followed by any character not=/ followed by .html

Try searching for this:
\/[^/]*.html

And replacing with this:
/

That should take care of the replacement part.
==============================

You could make a macro to do this Find and Replace, followed by
a select full line, then do a Find to find the current line and Mark All. Go to the first bookmark and remove the mark. Then delete all marked lines.

I think that will do it....NOTE: This is untested, just an untried concept that should be good.

Hope this helps.....good luck

===================
Subsequent editing note: I was working on this while Ed submitted his solution. As soon as mine was posted I saw his. Our Regex phrases are slightly different. Mine just deals with the trailing filename section, his treats the full line. I also wasn't aware of the sorting and delete duplicate tools. Thanks Ed. Learning every day! :D
Hope this was helpful.............good luck,
Bob
CitznFish
Posts: 2
Joined: Wed May 21, 2003 5:18 pm

Post by CitznFish »

Thank you both! This is exactly what i was looking for and my file is now edited. :)
Post Reply