SUMMARY: simple regex question

From: Christopher L. Barnard <>
Date: Mon Jan 31 2005 - 14:04:10 EST
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 <>
Alex Stade <>
Larry Anta <>
Kurt Schulte <>
Darren Dunham <>
Karyn Williams <>
Colin Bigam <>
Crist Clark <>
John Leadeham <>
David Markowitz <>
Hans Jacobsen <>
R A Lichtensteiger <>

| Christopher L. Barnard         O     When I was a boy I was told that |
|         / \    anybody could become president.  |
| (312) 347-4901               O---O   Now I'm beginning to believe it. |
|                --Clarence Darrow |
+----------PGP public key available via finger or PGP keyserver---------+
sunmanagers mailing list
Received 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