473,396 Members | 1,758 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

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

Regular expressions help

Given the following three lines:

name fredgeorge
name georgeharry
name george

I'm trying to find a regular expression that matches only the third
one.

My book resources are pretty skimpy when it comes to regular
expressions, and the stuff on the web I've found doesn't cover this
circumstance, and I can't figure out how to extrapolate from what is
described to my problem.

Can anyone help?

Thanks!
Jul 18 '05 #1
8 1269
Mike Hearne wrote on 24 Feb 2004 10:54:45 -0800:
Given the following three lines:

name fredgeorge
name georgeharry
name george

I'm trying to find a regular expression that matches only the third
one.


It's pretty easy:

"name george$"

"$" means end of string

--
Yours,

Andrei

=====
Real contact info (decode with rot13):
ce******@jnanqbb.ay. Fcnz-serr! Cyrnfr qb abg hfr va choyvp cbfgf. V ernq
gur yvfg, fb gurer'f ab arrq gb PP.
Jul 18 '05 #2
> name fredgeorge
name georgeharry
name george

I'm trying to find a regular expression that matches only the third
one.


'name george' would do, then ?!? If you mean 'george' on its
own as opposed to the previous variants, that'd be r'\bgeorge\b'.
One nifty tool to learn and experiment with re's is the
tools/scripts/redemo.py script normally present in your python installation.

Jul 18 '05 #3
Bernard Delmée wrote on Tue, 24 Feb 2004 20:36:50 +0100:
name fredgeorge
name georgeharry
name george

I'm trying to find a regular expression that matches only the third
one.


'name george' would do, then ?!? If you mean 'george' on its


That one matches the "name george" part of "name georgeharry" as well,
which he didn't want.

--
Yours,

Andrei

=====
Real contact info (decode with rot13):
ce******@jnanqbb.ay. Fcnz-serr! Cyrnfr qb abg hfr va choyvp cbfgf. V ernq
gur yvfg, fb gurer'f ab arrq gb PP.
Jul 18 '05 #4
> That one matches the "name george" part of "name georgeharry" as well,
which he didn't want.


Indeed; my bad. I mostly wanted to mention redemo, for which
the windows installer should create a shortcut, really...

Jul 18 '05 #5
Look in the module reference for REs, particularly the expression syntax
section:
http://www.python.org/doc/2.3.3/lib/re-syntax.html

You probably want either the $ or \b constructs. I'll let you decide
which is more appropriate for your task. You might alternately want the
(?! ... ) construct, but that's probably more complex than your needs.

HTH,
Mike

Mike Hearne wrote:
Given the following three lines:

name fredgeorge
name georgeharry
name george

I'm trying to find a regular expression that matches only the third
one.

....
_______________________________________
Mike C. Fletcher
Designer, VR Plumber, Coder
http://members.rogers.com/mcfletch/

Jul 18 '05 #6
> That one matches the "name george" part of "name georgeharry" as well,
which he didn't want.


Indeed; my bad. I mostly wanted to mention redemo, for which
the windows installer should create a shortcut, really...

Jul 18 '05 #7
> Mike Hearne wrote on 24 Feb 2004 10:54:45 -0800:
Given the following three lines:

name fredgeorge
name georgeharry
name george

I'm trying to find a regular expression that matches only the third
one.

* Andrei <fa**@fake.net> [2004-02-24 12:34]: It's pretty easy:

"name george$"

"$" means end of string


And if you'd also prefer not to match:

name name george

Then, you could match for:
"^name george$"

"^" means the beginning of the string.

-John
< my_first_name AT my_last_name DOT net >

Jul 18 '05 #8
Bernard Delmée wrote:
That one matches the "name george" part of "name georgeharry" as well,
which he didn't want.

Indeed; my bad. I mostly wanted to mention redemo, for which
the windows installer should create a shortcut, really...

Agreed
Jul 18 '05 #9

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

8
by: Massimo at HOME | last post by:
Probably, it is simple but honestly I am not able to solve this problem. I am trying to use eregi_replace() function to substitute some strings in my input. I would like to substitute the...
1
by: Stephajn Craig | last post by:
I'm thinking that I need to use a regular expression to make this work, but I'm not expert at them. What I'd like to do is be able to search a document for a specific word or words and when...
0
by: Andreas Klemt | last post by:
Hello, I have this HTML <a name=section1></a> <a href="myurl1_1.thm">Link1_1</a> <a href="myurl1_2.thm">Link1_2</a> <a href="myurl1_3.thm">Link1_3</a> <a name=section2></a> <a...
6
by: Schorschi | last post by:
This one has got me bam-boz-ald! or however your spell it... I have a sequence of text for example, "One Two Three Four Three Two One Three", and I need a regular expression, if possible, to...
3
by: JoeW | last post by:
Sorry if I am asking something has already been asked but I am somewhat stuck on a problem with regular expressions. My task is simple: take an HTTP url and remove all the characters after the...
4
by: Patrick C | last post by:
Kind programmers of the world: I've been lookign to learn python and when I tell people this they say "make sure you know RE" That's all well and good, and I read the tutorial but i'm...
10
by: supercrossking | last post by:
I am trying to the values of string of text in the sample before. The ds are for digits and s is for string and string of text is for a string with more than one or two values. I am trying to use...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.