Question

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

Was it helpful?

Solution

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

OTHER TIPS

try lookahead:

([^\s]+)(?=.*\tnumber)
(?:(\t([^\t ]*)))
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top