472,333 Members | 1,075 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,333 software developers and data experts.

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 17900
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Merlin | last post by:
Hello, I am trying to find out how to create a line of JS code to do a regex to match a URL inside a text. I don't want to know if it is valid,...
5
by: Bob | last post by:
I think this is very simple but I am having difficult doing it. Basically take a comma separated list: abc, def, ghi, jk A list with only one...
1
by: George Durzi | last post by:
Consider this excerpt from some HTML. (This is a copy from View->Source, except for the comment) <TABLE WIDTH=100% CELLPADDING=0 CELLSPACING=0...
6
by: Dan Hargrove | last post by:
I'm using the regex class to try and search a string for line feeds, carriage returns, and tabs. In a windows test app, I can enter the expression...
0
by: Tidane | last post by:
Visual Basic.NET Framework 2.0 I've created a program to parse out text as the program recieved it and use Regex matching to decide what should be...
10
by: bullockbefriending bard | last post by:
first, regex part: I am new to regexes and have come up with the following expression: ((1|),(1|)/){5}(1|),(1|) to exactly match strings which...
3
by: jwwest | last post by:
Anyone have any trouble pattern matching on lines returned by readline? Here's an example: string = "Accounting - General" pat = ".+\s-" ...
0
by: jagged | last post by:
I'm new to C# so am not completely familiar with its regular expression flavor and I don't understand why I can't get this to work. I set the...
0
by: saravanakumar muthurangan | last post by:
Hello all, i need to correct a misspelled word automatically with a most matching word by using MS word.dll in vb.net 2005, i m...
0
by: concettolabs | last post by:
In today's business world, businesses are increasingly turning to PowerApps to develop custom business applications. PowerApps is a powerful tool...
0
better678
by: better678 | last post by:
Question: Discuss your understanding of the Java platform. Is the statement "Java is interpreted" correct? Answer: Java is an object-oriented...
0
by: teenabhardwaj | last post by:
How would one discover a valid source for learning news, comfort, and help for engineering designs? Covering through piles of books takes a lot of...
0
by: CD Tom | last post by:
This happens in runtime 2013 and 2016. When a report is run and then closed a toolbar shows up and the only way to get it to go away is to right...
0
by: CD Tom | last post by:
This only shows up in access runtime. When a user select a report from my report menu when they close the report they get a menu I've called Add-ins...
0
by: Naresh1 | last post by:
What is WebLogic Admin Training? WebLogic Admin Training is a specialized program designed to equip individuals with the skills and knowledge...
0
jalbright99669
by: jalbright99669 | last post by:
Am having a bit of a time with URL Rewrite. I need to incorporate http to https redirect with a reverse proxy. I have the URL Rewrite rules made...
0
by: Matthew3360 | last post by:
Hi there. I have been struggling to find out how to use a variable as my location in my header redirect function. Here is my code. ...
2
by: Matthew3360 | last post by:
Hi, I have a python app that i want to be able to get variables from a php page on my webserver. My python app is on my computer. How would I make it...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.