Search code examples
regexbashnon-greedy

Match until the first occurance of a symbol


Suppose we have a file containing lines of the following form (but the number of #'s is not fixed, and the length of fields is not fixed)

as#dviu#cvm#ud

For the above line, .*# matches as#dviu#cvm# (i.e. it goes as far as possible). How to match until the first occurrence of #? (i.e. match only as#)


Solution

  • Use [^#], instead of ., to match anything except a #.