Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

wildcard char in emacs search and replace?

3,433 views
Skip to first unread message

Huma Ahmad

unread,
Jun 2, 1998, 3:00:00 AM6/2/98
to

Hi all,

I was wondering if anyone knew how to search and replace a string in
emacs with wildcards.

I am editing my netscape bookmarks in emacs and want to delete all the
occurences of ADD_DATE="039430439" , ADD_DATE="3039393", etc, etc...

replace-string will replace one but i want it to search the entire
document and replace all of them

M-x replace-string ADD_DATE="*" with (blank) doesn't seem to work

I checked all the faq's and manuals but cant seem to find anything?

Any help is appreciated, Thanx


Huma Ahmad http://come.to/jannah ha4...@csc.albany.edu
-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
God is the Helper and Protector of those who believe in Him:
He brings them out of the depths of darkness into the light...(2:257)


Juan Leon Lahoz Garcia

unread,
Jun 2, 1998, 3:00:00 AM6/2/98
to

Huma Ahmad <ha4...@csc.albany.edu> writes:

> I was wondering if anyone knew how to search and replace a string in
> emacs with wildcards.

...


> M-x replace-string ADD_DATE="*" with (blank) doesn't seem to work
>

C-h f replace-regexp should help. ("string with wildcards" is a
subtype of REGular EXPression).

In particular
M-x replace-regexp ADD_DATE=.* with (blank) must work.

--
Leon

Steve Gonedes

unread,
Jun 2, 1998, 3:00:00 AM6/2/98
to

Huma Ahmad <ha4...@csc.albany.edu> writes:

<
<
< Hi all,


<
< I was wondering if anyone knew how to search and replace a string in
< emacs with wildcards.
<

< I am editing my netscape bookmarks in emacs and want to delete all the
< occurences of ADD_DATE="039430439" , ADD_DATE="3039393", etc, etc...
<
< replace-string will replace one but i want it to search the entire
< document and replace all of them
<

< M-x replace-string ADD_DATE="*" with (blank) doesn't seem to work

There is a section in the elisp manual (emacs)Regexps: that gives some
nice examples of how to use emacs lisp regexps.

What you're doing is trying to match lots of `"' characters in a row.
Try

M-x replace-string ADD_DATE="[0-9]+"

where [0-9]+ is like `many numbers in a row'. For more exact details
see the info node (it does a much better job explaining regexps that
me).


Harry Putnam

unread,
Jun 2, 1998, 3:00:00 AM6/2/98
to

Huma Ahmad <ha4...@csc.albany.edu> writes:

> Hi all,
>
> I was wondering if anyone knew how to search and replace a string in
> emacs with wildcards.

Use query replace by regexp (M-x query-replace-regexp)

> I am editing my netscape bookmarks in emacs and want to delete all the
> occurences of ADD_DATE="039430439" , ADD_DATE="3039393", etc, etc...
>
> replace-string will replace one but i want it to search the entire
> document and replace all of them
>
> M-x replace-string ADD_DATE="*" with (blank) doesn't seem to work
>

> I checked all the faq's and manuals but cant seem to find anything?

You are trying to use 'wildcards' and globbing. Whereas emacs wants
regular expression syntax. Read those sections in Emacs info
'Query Replace' and 'Regular Expressions' it will take some study to
see how it works. In brief:

FROM regular expression ("ADD_DATE=.*[0-9]") <== no parens

will find the two samples you gave (probably good for all of them)
It searches for ADD_DATE= followed by any charactes except newlines,
then ending with any digit 0-9 followed by a " (double quote mark)

TO for a replace string just hit <RET> so. . .

FROM "ADD_DATE=.*[0-9]"<RET>
TO <RET>

When it takes you to the first one press ? (question mark) to see an
explanation of how to do them all at once or one by one.

--

Harry Putnam rea...@newsguy.com

Ueli Schlaepfer

unread,
Jun 3, 1998, 3:00:00 AM6/3/98
to

Huma Ahmad <ha4...@csc.albany.edu> writes


> I was wondering if anyone knew how to search and replace a string in
> emacs with wildcards.

Regular Expressions are what you want in such cases.

Try

M-x replace-regexp RET ADD_DATE="[0-9]+" RET SPC RET

instead of replace-string.

And make sure you check out the documentation on regexps, they are very
useful for lots of things.

Good luck,
Ueli

--
Mitsubishi Electric Corp. 1-1, Tsukaguchi-Honmachi 8-Chome
IESL (Building Mechatronics) Amagasaki, Hyogo 661, Japan
Tel: ++81-(0)6 497-7672 Fax: ++81-(0)6 497-7726

Jega Aravandy

unread,
Jun 3, 1998, 3:00:00 AM6/3/98
to Huma Ahmad

Try this:
M-x query-replace-regexp
Replace regexp: ADD_DATE="[0-9]+"
with:
This will prompt you for confirmation
If you want to replace without confirmation then try
M-x replace-regexp
The replace regular expression assumes that their are only
number after "ADD_DATE=".

Hope this help.

Jega


Huma Ahmad wrote:

> Hi all,


>
> I was wondering if anyone knew how to search and replace a string in
> emacs with wildcards.
>

> I am editing my netscape bookmarks in emacs and want to delete all the
> occurences of ADD_DATE="039430439" , ADD_DATE="3039393", etc, etc...
>
> replace-string will replace one but i want it to search the entire
> document and replace all of them
>
> M-x replace-string ADD_DATE="*" with (blank) doesn't seem to work
>
> I checked all the faq's and manuals but cant seem to find anything?
>

> Any help is appreciated, Thanx
>
> Huma Ahmad http://come.to/jannah ha4...@csc.albany.edu
> -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
> God is the Helper and Protector of those who believe in Him:
> He brings them out of the depths of darkness into the light...(2:257)

--
Jega Aravandy
AddVal Technology Inc.
je...@addval.com (408) 524 6301


0 new messages