tags:

views:

96

answers:

3

I am trying to get the first word in the line that matches the whole word 'number'. But I am only interested where whole word 'number' is matched and is preceded by a tab.

For example if following is the text:

tin identification number 4/10/2007 LB
num number 9/27/2006 PAT

I want to get back num

Regex I have is:

match whole word: \bnumber\b

if above is found then get first word: ([^\s]*)

I think I need modification in match whole word regex so that it only matches when whole word is preceded by a tab

+3  A: 

This answer depends a bit on your regex engine as they can have different representations for tab. In the .Net regex engine though it would look like ...

\tnumber
JaredPar
but will that also match whole word 'number'. what if the string has [tab]numberOne then I dont want to match that. can I modify your answer to be \t\bnumber\b ?
Drake
actually, just tried what I suggested. that works. thanks
Drake
I'll accept your answer but please edit it for someone who has a similar problem.
Drake
A: 
(?:(\t([^\t ]*)))
A: 

try lookahead:

([^\s]+)(?=.*\tnumber)
SilentGhost