tags:

views:

431

answers:

4

I have the following line:

hshd    household 8/29/2007 LB

I want to match anything that comes before the first space (whitespace). So, in this case, I want to get back

hshd
+1  A: 

Perhaps you could try ([^ ]+) .*, which should give you everything to the first blank in your first group.

dsolimano
You don't need the '.*'
ire_and_curses
+2  A: 
([^\s]+)

works

SilentGhost
I would further prepend ^ to get the first word only
soulmerge
while generally correct, I think the need for `^` depends on particular language implementations or regexp. for example in Python you'd use `re.match` for this task.
SilentGhost
+1  A: 

This should do it:

^\S*
Jeremy Stein
+1  A: 

for the entire line

^(\w+)\s+(\w+)\s+(\d+(?:\/\d+){2})\s+(\w+)$
w35l3y