469,342 Members | 5,664 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,342 developers. It's quick & easy.

Regex matching 3rd word in a line?

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.
Ian

Jul 18 '05 #1
3 15567
Ian Gil wrote:
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.

Peace,
Joe

Jul 18 '05 #2
>> 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
Jul 18 '05 #3
Ian Gil wrote:
and I'm looking to match just the third word.


Hm, first extract the third word and then use re?
s = "one two three four"
s.split()[2]

'three'

split has an optional argument "sep" to define other chars than
whitespace characters.

--
Gruß - regards
Klaus :-)

Jul 18 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

2 posts views Thread by Merlin | last post: by
1 post views Thread by George Durzi | last post: by
6 posts views Thread by Dan Hargrove | last post: by
reply views Thread by Tidane | last post: by
10 posts views Thread by bullockbefriending bard | last post: by
3 posts views Thread by jwwest | last post: by
1 post views Thread by CARIGAR | last post: by
reply views Thread by suresh191 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.