I needed to do this when I was parsing some output. The problem is like this: given a string say "foo[] boo[] more goo[] more" and wanted to look for pattern like this "__["
In other words, a letter or more that end with "[", but needed to find the first one. Hence in the above, I wanted to find "foo".
2 ways to do this:
s = "foo[] boo[] more goo[] more"; StringCases[s, RegularExpression["^\\w*\\["]] Out[265]= {foo[}
and
StringCases[s, Shortest[StartOfString~~__~~"["], Overlaps -> False] Out[266]= {foo[}