* How to search a whole word in emacs? @ 2007-10-26 18:08 webinfinite 2007-10-26 21:08 ` Amy Templeton ` (3 more replies) 0 siblings, 4 replies; 9+ messages in thread From: webinfinite @ 2007-10-26 18:08 UTC (permalink / raw) To: help-gnu-emacs I need to search a whole word in a big file. For example, I need to search "Machine" but I don't need to know anything like "machine_state", "running_machine_state" etc. The search shall be case sensitive. I've tried C-s ret C-w Machine but it returns every word with "Machine" in it. I just need the exact word. Thank you for your help. ^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: How to search a whole word in emacs? 2007-10-26 18:08 How to search a whole word in emacs? webinfinite @ 2007-10-26 21:08 ` Amy Templeton 2007-10-26 21:08 ` Eric Hanchrow ` (2 subsequent siblings) 3 siblings, 0 replies; 9+ messages in thread From: Amy Templeton @ 2007-10-26 21:08 UTC (permalink / raw) To: help-gnu-emacs "webinfinite@gmail.com" <webinfinite@gmail.com> wrote: > I need to search a whole word in a big file. For example, I need to search > "Machine" but I don't need to know anything like "machine_state", > "running_machine_state" etc. The search shall be case sensitive. > I've tried C-s ret C-w Machine but it returns every word with "Machine" in > it. I just need the exact word. Dear Web, The following should do the trick, searching for the word "machine" either at the beginning of a line and followed by a space, surrounded by spaces, or preceded by a space and at the end of a line. Type the following (not the bit with the dashes, though): -----------------|CODE|----------------- M-x re-search-forward RET \(^\|[ \t]\)machine\([ \t]\|$\) ---------------------------------------- It's probably more constructive to copy the regexp than to type it all in. This will place your cursor at the *end* of whatever it finds. For more information, the section in the Info system on regexps is useful. Amy -- A day without orange juice is like a day without orange juice. ^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: How to search a whole word in emacs? 2007-10-26 18:08 How to search a whole word in emacs? webinfinite 2007-10-26 21:08 ` Amy Templeton @ 2007-10-26 21:08 ` Eric Hanchrow 2007-10-26 21:54 ` David Hansen 2007-10-26 22:05 ` Drew Adams 2007-10-27 9:45 ` Johan Bockgård [not found] ` <mailman.2615.1193432708.18990.help-gnu-emacs@gnu.org> 3 siblings, 2 replies; 9+ messages in thread From: Eric Hanchrow @ 2007-10-26 21:08 UTC (permalink / raw) To: help-gnu-emacs I need to search a whole word in a big file. For example, I need to search "Machine" but I don't need to know anything like "machine_state", "running_machine_state" etc. The search shall be case sensitive. I've tried C-s ret C-w Machine but it returns every word with "Machine" in it. I just need the exact word. You want either M-C-s \ b M a c h i n e \ b or perhaps M-x word-search-forward RET Machine RET -- Asking the Iraqi people to assume Saddam's debts is rather like telling a man who has been shot in the head that he has to pay for the bullet. -- James Surowiecki ^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: How to search a whole word in emacs? 2007-10-26 21:08 ` Eric Hanchrow @ 2007-10-26 21:54 ` David Hansen 2007-10-27 10:10 ` Dieter Wilhelm 2007-10-26 22:05 ` Drew Adams 1 sibling, 1 reply; 9+ messages in thread From: David Hansen @ 2007-10-26 21:54 UTC (permalink / raw) To: help-gnu-emacs On Fri, 26 Oct 2007 14:08:24 -0700 Eric Hanchrow wrote: > M-x word-search-forward RET Machine RET aka C-s RET ^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: How to search a whole word in emacs? 2007-10-26 21:54 ` David Hansen @ 2007-10-27 10:10 ` Dieter Wilhelm 0 siblings, 0 replies; 9+ messages in thread From: Dieter Wilhelm @ 2007-10-27 10:10 UTC (permalink / raw) To: help-gnu-emacs David Hansen <david.hansen@gmx.net> writes: > On Fri, 26 Oct 2007 14:08:24 -0700 Eric Hanchrow wrote: > >> M-x word-search-forward RET Machine RET > > aka C-s RET Super! Thanks a lot. By the way, this is not documented for C-s (isearch-forward). only in: (info-other-window "(emacs)Special Isearch") -- Best wishes H. Dieter Wilhelm Darmstadt, Germany ^ permalink raw reply [flat|nested] 9+ messages in thread
* RE: How to search a whole word in emacs? 2007-10-26 21:08 ` Eric Hanchrow 2007-10-26 21:54 ` David Hansen @ 2007-10-26 22:05 ` Drew Adams 1 sibling, 0 replies; 9+ messages in thread From: Drew Adams @ 2007-10-26 22:05 UTC (permalink / raw) To: help-gnu-emacs > I need to search a whole word in a big file. For example, I need to > search "Machine" but I don't need to know anything like > "machine_state", "running_machine_state" etc. The search shall be case > sensitive. > > I've tried C-s ret C-w Machine but it returns every word with > "Machine" in it. I just need the exact word. Assuming that "ret" means hit the Enter key (usually written RET), that should work fine (assuming you also follow it by another RET). It should not find "Machine" in the middle of other words; it should find it only as a whole word. It is a non-incremental search, however, which is usually less convenient than incremental search. > You want either M-C-s \ b M a c h i n e \ b That's incremental and works fine, but can be a bit hard to remember. > or perhaps M-x word-search-forward RET Machine RET Aother way to do incremental word search (also a bit hard to remember): C-s M-e C-w M a c h i n e C-s Starting with Emacs 22, this is documented in the Emacs manual (node Word Search). Another way, if you use Isearch+ (http://www.emacswiki.org/cgi-bin/wiki/IsearchPlus): C-s M-w M a c h i n e This (`isearch-toggle-word') is from Juri Linkov, BTW. I thought it was going to be added to Emacs a year ago, but it looks like it never was. Too bad. An advantage is that `M-w' is a toggle between word and non-word search - use it at any time. ^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: How to search a whole word in emacs? 2007-10-26 18:08 How to search a whole word in emacs? webinfinite 2007-10-26 21:08 ` Amy Templeton 2007-10-26 21:08 ` Eric Hanchrow @ 2007-10-27 9:45 ` Johan Bockgård [not found] ` <mailman.2615.1193432708.18990.help-gnu-emacs@gnu.org> 3 siblings, 0 replies; 9+ messages in thread From: Johan Bockgård @ 2007-10-27 9:45 UTC (permalink / raw) To: help-gnu-emacs "webinfinite@gmail.com" <webinfinite@gmail.com> writes: > I need to search a whole word in a big file. For example, I need to > search "Machine" but I don't need to know anything like > "machine_state", "running_machine_state" etc. The search shall be case > sensitive. > > I've tried C-s ret C-w Machine but it returns every word with > "Machine" in it. I just need the exact word. `running_machine_state' usually counts as a symbol consisting of three words. You need to search for symbol, not word, boundaries (works only in Emacs >= 22): C-M-s \_<Machine\_> -- Johan Bockgård ^ permalink raw reply [flat|nested] 9+ messages in thread
[parent not found: <mailman.2615.1193432708.18990.help-gnu-emacs@gnu.org>]
* Re: How to search a whole word in emacs? [not found] ` <mailman.2615.1193432708.18990.help-gnu-emacs@gnu.org> @ 2007-11-23 0:44 ` David Combs 2007-11-23 8:26 ` Xah Lee 0 siblings, 1 reply; 9+ messages in thread From: David Combs @ 2007-11-23 0:44 UTC (permalink / raw) To: help-gnu-emacs Amy Templeton <amy.g.templeton@gmail.com> wrote: ... > >For more information, the section in the Info system on regexps is useful. > >Amy For *VASTLY* more information, plus examples galore, plus explanations, etc, don't even think of using regexps without first acquiring the book (well, "bible"): Mastering Regular Expressions, 2nd Edition By [54]Jeffrey E. F. Friedl 2nd Edition July 2002 0-596-00289-0, Order Number: 2890 484 pages, $39.95 US $61.95 CA #28.50 UK Much cheaper (eg 40% off) at www.bookpool.com. This book is the regexp-bible for the planet -- covers emacs, perl, php, egrep, java, you name it. Scan through the book, and you won't understand how you thought you knew what you were doing before you got the book. To convince her and others to get it, how about some comments from those who've got the book? THANKS! David ^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: How to search a whole word in emacs? 2007-11-23 0:44 ` David Combs @ 2007-11-23 8:26 ` Xah Lee 0 siblings, 0 replies; 9+ messages in thread From: Xah Lee @ 2007-11-23 8:26 UTC (permalink / raw) To: help-gnu-emacs David Combs wrote: <<...Mastering Regular Expressions, By Jeffrey E. F. Friedl... To convince her and others to get it, how about some comments from those who've got the book?>> I read it in its entirety in 1999. (first edition) I think it is a excellent book. However, i don't think it as a practical, necessary, book, for average professional programers who works with text a lot (such as web app developers and sys admins). Because: * in my extensive use of regexes, daily, since about 1998 working in the web application industry and sys admin, i only need to use advanced regex maybe once or twice a year. * most complex regexes needs, are more practical to be implemented by breaking down into 2 patterns to test on (as opposed to a single complex regex). * when you need advanced regexes, the regex very quickly cannot handle the job. You need either to break it into several regexes with nested if statements, or you need a parser. in the above, by "advanced regexes" i mean non-grouping constructs of the form (?...), boundary anchors, nested patterns... etc. ------------------- related articles i've wrote: * Pyhton Regex Documentation: String Pattern Matching (complete rewrite of python's re module doc.) http://xahlee.org/perl-python/python_re-write/lib/module-re.html * Simple intro to emacs's regex http://xahlee.org/emacs/emacs_regex.html * Emacs Lisp regex doc http://xahlee.org/elisp/Regular-Expressions.html Xah xah@xahlee.org \xAD\xF4 http://xahlee.org/ > To convince her and others to get it, how about > some comments from those who've got the book? On Nov 22, 4:44 pm, dkco...@panix.com (David Combs) wrote: > Amy Templeton <amy.g.temple...@gmail.com> wrote: > ... > > > > >For more information, the section in the Info system on regexps is useful. > > >Amy > > For *VASTLY* more information, plus examples galore, plus explanations, > etc, don't even think of using regexps without first acquiring the book > (well, "bible"): > > Mastering Regular Expressions, 2nd Edition > By [54]Jeffrey E. F. Friedl > 2nd Edition July 2002 > 0-596-00289-0, Order Number: 2890 > 484 pages, $39.95 US $61.95 CA #28.50 UK > > Much cheaper (eg 40% off) atwww.bookpool.com. > > This book is the regexp-bible for the planet -- covers > emacs, perl, php, egrep, java, you name it. > > Scan through the book, and you won't understand how you > thought you knew what you were doing before you got the book. > > To convince her and others to get it, how about > some comments from those who've got the book? > > THANKS! > > David ^ permalink raw reply [flat|nested] 9+ messages in thread
end of thread, other threads:[~2007-11-23 8:26 UTC | newest] Thread overview: 9+ messages (download: mbox.gz follow: Atom feed -- links below jump to the message on this page -- 2007-10-26 18:08 How to search a whole word in emacs? webinfinite 2007-10-26 21:08 ` Amy Templeton 2007-10-26 21:08 ` Eric Hanchrow 2007-10-26 21:54 ` David Hansen 2007-10-27 10:10 ` Dieter Wilhelm 2007-10-26 22:05 ` Drew Adams 2007-10-27 9:45 ` Johan Bockgård [not found] ` <mailman.2615.1193432708.18990.help-gnu-emacs@gnu.org> 2007-11-23 0:44 ` David Combs 2007-11-23 8:26 ` Xah Lee
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox; as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).