Take the 2-minute tour ×  I know there are many examples of a
non-greedy regex with grep, but I'm having problems with my
specific case.  My file contains lines similar to:   and I'm
trying to parse out just the X12345 part. That is, the part
starting with X and up until the first period (.)  My closest
example so far is:  grep -Eo "X(.*?)\."  inputfile  But that is
too greedy (even though I think I used .*? properly.  Can
someone help guide me to a proper regex?  share|improve this
question why grep ? This sounds like a job for cut -d '.' -f1 |
cut -d '[' -f2, to me. –  Sirex Aug 9 '12 at 0:14  1 Answer 1
up vote 2 down vote accepted  You are using .* properly but as
you noticed it is greedily eating up as many characters as it
can in your match because . matches any character. You could do:
grep -Eo "X([^.]*?)\." inputFile  This matches an X followed by
any length sequence of any non dot ([^.]*) up to some character
(?) and a dot (\.). You say you are interested in everything
between the first X and the f