Regex matching 3rd word in a line?
Ian Gil
i at NOSPAMALLOWED.com
Fri Oct 31 03:45:57 EST 2003
>> I'm looking to match the 3rd (or whatever) word in a line, where word
>> can be anything that's not white space.
>>
>> I'm not programming, but I'm using a program which says it uses python
>> style regular expressions.
>>
>
> This will match the third word in a line:
>
> ^(?:\S+\s){2}(\S+)
>
> Change the "2" to "whatever - 1" to match a different word.
This worked except it's matching from the beginning up to the third word
and I'm looking to match just the third word. I tried some variations of
it but apparently not the right ones.
Thanks,
Ian
More information about the Python-list
mailing list