Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > startswith() and endswith() for re's would be more intuitive

Reply
Thread Tools

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

 
 
metaperl
Guest
Posts: n/a
 
      09-28-2006
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.

 
Reply With Quote
 
 
 
 
Bruno Desthuilliers
Guest
Posts: n/a
 
      09-28-2006
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 '(E-Mail Removed)'.split('@')])"
 
Reply With Quote
 
 
 
 
John Salerno
Guest
Posts: n/a
 
      09-28-2006
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.
 
Reply With Quote
 
metaperl
Guest
Posts: n/a
 
      09-28-2006

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.

 
Reply With Quote
 
Fredrik Lundh
Guest
Posts: n/a
 
      09-28-2006
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>

 
Reply With Quote
 
Lawrence D'Oliveiro
Guest
Posts: n/a
 
      09-29-2006
In message <(E-Mail Removed) .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.
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
SIMPLE! and INTUITIVE! GUI BUILDER for RUBY? gcarcass Ruby 14 05-08-2007 02:30 PM
Analytical or Intuitive? elena Java 25 04-12-2005 04:19 AM
Analytical or Intuitive? elena@monmouth.com C++ 0 04-07-2005 11:50 PM
Counter Intuitive Results: Optimising an FFT routine for Speed Paul Brown C Programming 7 10-10-2003 06:38 AM
Counter Intuitive Results: Optimising an FFT routine for Speed Paul Brown C Programming 4 10-09-2003 08:33 PM



Advertisments