473,386 Members | 1,726 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,386 software developers and data experts.

startswith() and endswith() for re's would be more intuitive

I just finished answering a question in #python because someone tried
to match using ... well.. match()
but did not realize that match() is actually startswith() for regexps.

I suggest:
re.compile('blah').atstartof(string)
re.compile('blah').atendof(string)

But it will never happen.

Sep 28 '06 #1
5 4696
metaperl wrote:
I just finished answering a question in #python because someone tried
to match using ... well.. match()
but did not realize that match() is actually startswith() for regexps.
Yet someone else that failed to read the Fine Manual(tm).
I suggest:
re.compile('blah').atstartof(string)
re.compile('blah').atendof(string)
What's wrong with:
re.search(r'^blah', somestring)
re.search(r'blah$', somestring)
--
bruno desthuilliers
python -c "print '@'.join(['.'.join([w[::-1] for w in p.split('.')]) for
p in 'o****@xiludom.gro'.split('@')])"
Sep 28 '06 #2
Bruno Desthuilliers wrote:
metaperl wrote:
>I just finished answering a question in #python because someone tried
to match using ... well.. match()
but did not realize that match() is actually startswith() for regexps.

Yet someone else that failed to read the Fine Manual(tm).
>I suggest:
re.compile('blah').atstartof(string)
re.compile('blah').atendof(string)

What's wrong with:
re.search(r'^blah', somestring)
re.search(r'blah$', somestring)
I think, since he even said himself that "match() is actually
startswith() for regexps", that he isn't complaining about the lack of
this feature, just that he wants a name change. Otherwise I'm not sure
what he wants.
Sep 28 '06 #3

Bruno Desthuilliers wrote:
metaperl wrote:
I just finished answering a question in #python because someone tried
to match using ... well.. match()
but did not realize that match() is actually startswith() for regexps.

Yet someone else that failed to read the Fine Manual(tm).
I suggest:
re.compile('blah').atstartof(string)
re.compile('blah').atendof(string)

What's wrong with:
re.search(r'^blah', somestring)
re.search(r'blah$', somestring)
Nothing. There is also nothing wrong with

re.match('blah', somestring)

but it does read as well as

re.atstartof('blah', something)

and the counterpart for EOS is not there.

Sep 28 '06 #4
metaperl wrote:
Nothing. There is also nothing wrong with

re.match('blah', somestring)

but it does read as well as

re.atstartof('blah', something)
yuck.
and the counterpart for EOS is not there.
sure is; it's spelled:

re.match('.*blah$', somestring)

</F>

Sep 28 '06 #5
In message <11**********************@k70g2000cwa.googlegroups .com>, metaperl
wrote:
There is also nothing wrong with

re.match('blah', somestring)

but it does read as well as

re.atstartof('blah', something)

and the counterpart for EOS is not there.
The only reason for those special cases for simple string matching is
precisely because string matching is so simple and so limited. Whereas
regular expressions give you so much more power--you can match at the
start, at the end, somewhere in the middle, 3 characters from the end, and
myriads of other possibilities. All of these can be succinctly expressed in
the RE notation itself, so there's no need for lots of special-case calls.
Sep 29 '06 #6

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

Similar topics

21
by: Michele Simionato | last post by:
I often feel the need to extend the string method ".endswith" to tuple arguments, in such a way to automatically check for multiple endings. For instance, here is a typical use case: if...
39
by: Erlend Fuglum | last post by:
Hi everyone, I'm having some trouble sorting lists. I suspect this might have something to do with locale settings and/or character encoding/unicode. Consider the following example, text...
1
by: Robin Tucker | last post by:
Hi, I would like to select records from a table where the following criteria hold: SELECT * from Mytable where field x "contains" string @X or
4
by: Mark Stijnman | last post by:
A while ago I posted a question about how to get operator behave differently for reading and writing. I basically wanted to make a vector that can be queried about whether it is modified recently...
6
by: LongBow | last post by:
Hello all, I am having a little problems getting String's StartsWith and EndsWith methods. If I have a string defined as sNormalPt which equals "0x11D0" then use the following command ...
18
by: Zytan | last post by:
I want the same function to be run whether you press Enter or double click the listbox. It seems really verbose to write both handlers to both events everytime, even if they both call the same...
4
by: =?utf-8?B?Qm9yaXMgRHXFoWVr?= | last post by:
Hello, what is the use-case of parameter "start" in string's "endswith" method? Consider the following minimal example: a = "testing" suffix="ing" a.endswith(suffix, 2) Significance of...
11
by: cjt22 | last post by:
Hi startswith( prefix]) States: Return True if string starts with the prefix, otherwise return False. prefix can also be a tuple of suffixes to look for. However when I try and add a tuple...
4
by: zacks | last post by:
I need to check the current value of a string value to see if it either starts with or ends with a double quote character, as in "123" (where the quotes are actual contens of the string). I thought...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...

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.