SUMMARY: simple regex question

From: Christopher L. Barnard (cbar44_at_tsg.cbot.com)
Date: 01/31/05

  • Next message: Stanley Laufer: "Solaris 9 /etc/shadow file, $ character as first entry."
    Date: Mon, 31 Jan 2005 13:04:10 -0600 (CST)
    To: sunmanagers@sunmanagers.org
    
    

    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/sunmanagers


  • Next message: Stanley Laufer: "Solaris 9 /etc/shadow file, $ character as first entry."

    Relevant Pages

    • Re: Leading whitespace in data being stripped out
      ... I would suggest that you put the tab in the appropriate place in the mail ... Please reply to the newsgroup unless you wish to avail yourself of my ... with a tab character now seems to be ignoring\striping the leading tab ... How do I get office 2007 to not ignore\strip leading whitespace ...
      (microsoft.public.word.mailmerge.fields)
    • Re: Formatting index entries
      ... replace each space with a tab character ... Copy the whole cell ... use Edit>Replace to replace every tab with a space. ... you want to rip all the Index tags out of the main document. ...
      (microsoft.public.mac.office.word)
    • Re: Browsers browsers
      ... :> then opens in another window to see the line with the error. ... :> Address Bar Location Bar ... :> There is a New Tab button which is handy once, ...
      (microsoft.public.scripting.jscript)
    • Re: sscanf or vsscanf : want to scan a list of integers in c
      ... Is the whitespace significant? ... You can't do that with any standard sscanf(): ... space, tab, newline, or other whitespace: ...
      (comp.lang.c)
    • Re: Browsers browsers
      ... :> then opens in another window to see the line with the error. ... :> Address Bar Location Bar ... :> There is a New Tab button which is handy once, ...
      (microsoft.public.scripting.jscript)