By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
443,275 Members | 1,745 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 443,275 IT Pros & Developers. It's quick & easy.

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

P: n/a
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
Share this Question
Share on Google+
5 Replies


P: n/a
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

P: n/a
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

P: n/a

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

P: n/a
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

P: n/a
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 discussion thread is closed

Replies have been disabled for this discussion.