Search and replace with wildcard

Tool for Search and Replace across multiple files.
Post Reply
User avatar
JimLaw

Search and replace with wildcard

Post by JimLaw »

How can I do a search and replace with wildcards?

I need to search for text eg:

"Title of a book, author of a book, date"
and replace with
"Title of a book, date"

REPLACE Title of book,*date WITH Title of book, date

If tried using * ? etc but can't seem to do it.

Help anyone?

User avatar
DV

Post by DV »

You could use a regular expression replace -

RegEx: (Title of a book), (author of a book), (date)
Replace: $1,$3

The brackets () create capturing groups, which you reference in your replace expression using $1, $2, etc.

If you don't know the the Author, you could use a wildcard (.*) + capturing group -
(Title of a book), (.*), (date)

The regex tester screen is helpful for designing these.
User avatar
Fool4UAnyway

Post by Fool4UAnyway »

Wouldn't the following regex be the preferred choice?

(Title of a book), ([^,]*), (date)

The author, of course, doesn't need to be captured and referenced. (I don't know if this improves the performance in any way, DV?)

Find:
(Title of a book), [^,]*, (date)

Replace:
$1, $2
Post Reply