I asked: > I have a quick regexp question. > > I want to match, case does not matter, a string > foo: bar > where foo starts the line, there can be one or more whitespace characters > between the : and the bar, and there can be zero or more whitespace > characters between the bar and the end of line. "whitespace characters" > here means spaces or tabs. > > /usr/bin/egrep -i ^foo:[ ][ ]*bar[ ]*$ > > works with any combination of spaces I use. But when I add \t to the regex: > > /usr/bin/egrep -i ^foo:[ \t][ \t]*bar[ \t]*& > > it fails. I have tried escaping the \t (as in, \\t), but that did not help. > I tried bracketing with ( and ), but that did not help. I have used double > and single quotes, and that did not help. Can anyone suggest how to write an > RE that will see a tab character? TIA and I will summarize. The answer: The "\t" is how it is written down in documentation. But to use the tab character in a regex, hit the tab key. literally. It works like a charm. For the individuals who suggested /:space:/ : yes, that would work in a more powerful shell. I want this to work in the basic /bin/sh, and understanding of /:space:/ in egrep is something added in ksh. For the individuals who did not understand why I would have the [ =t]*$ at the end: that will capture whitespace between what looks like the last character of the string and the end-of-line. Whitespace at the end doesn't harm anything, so there is no reason to check for it. I also got a few links to get the hex code for a tab. Thanks. (TAB= \011). Thanks to: Doc G <maddocg@verizon.net> Alex Stade <alex@trdlnk.com> Larry Anta <lanta@ryerson.ca> Kurt Schulte <r2kurts@yahoo.com> Darren Dunham <ddunham@taos.com> Karyn Williams <karyn@calarts.edu> Colin Bigam <colin@west.gecems.com> Crist Clark <crist.clark@globalstar.com> John Leadeham <jl@lammtarra.fslife.co.uk> David Markowitz <DMarkowitz@litronic.com> Hans Jacobsen <HJacobsen@grandcentral.com> R A Lichtensteiger <sunmanagers@throwawaydomain.com> +-----------------------------------------------------------------------+ | Christopher L. Barnard O When I was a boy I was told that | | cbarnard@tsg.cbot.com / \ anybody could become president. | | (312) 347-4901 O---O Now I'm beginning to believe it. | | http://www.cs.uchicago.edu/~cbarnard --Clarence Darrow | +----------PGP public key available via finger or PGP keyserver---------+ _______________________________________________ sunmanagers mailing list sunmanagers@sunmanagers.org http://www.sunmanagers.org/mailman/listinfo/sunmanagersReceived on Mon Jan 31 14:05:53 2005
This archive was generated by hypermail 2.1.8 : Thu Mar 03 2016 - 06:43:43 EST