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

[perl-python] string pattern matching

# -*- coding: utf-8 -*-
# Python

# Matching string patterns
#
# Sometimes you want to know if a string is of
# particular pattern. Let's say in your website
# you have converted all images files from gif
# format to png format. Now you need to change the
# html code to use the .png files. So, essentially
# you want to replace strings of the form
#
# img src="*.gif"
# to
# img src="*.png"
#
# Python provides string pattern matching by the
# "re" module. (String Pattern Matching is
# inanely known as Regular Expression (regex) in
# the computing industry. It is a misnomer and
# causes great unnecessary confusion.)
©import re
©
©text='''<img src="../Icons_dir/icon_sum.gif" width="32"
height="32">'''
©
©pattern = r'''src="([^"]+)\.gif"'''
©
©result = re.search(pattern, text)
©
©if result:
© print 'yes'
© print result.expand(r"\1") # the captured pattern
©else:
© print 'no'

#-------------
# if re.search(pattern, text) does not match, then the result is
None. If it matches, an object is returned. One can then use methods
such as .groups(), .expand(), .split() ... to find the matched parts,
or a given replacement string, or split the text into multiple part
by the regex...

# regex is quite confusing for beginners, but
# isn't really difficult to understand. It comes
# with practice.

# see
# http://python.org/doc/lib/module-re.html
# for detail.

# i'll have to study more to make complet example. Try it yourself.

-----------------

# in perl, regex is its mainstay.
# very expressive with syntax, but not so in semantic,
# when compared to Python.

# for syntax variability, for example the following are all the same.

$text = "what ever is here to be matched";

if ( $text =~ ever) { print 'yes'} else {print "no"}
if ( $text =~ /ever/) { print 'yes'} else {print "no";}
if ( $text =~ m/ever/) { print 'yes'} else {print "no"}
if ( $text =~ m(ever)) { print 'yes'} else {print "no"}
if ( $text =~ m@ever@) { print 'yes'} else {print "no"}

# for detail of its much ado about nothing nature,
# see perldoc perlre

--------
this is perl-python a-day mailing list. To subscribe, see
http://xahlee.org/perl-python/python.html
Xah
xa*@xahlee.org
http://xahlee.org/PageTwo_dir/more.html

Jul 18 '05 #1
9 3160
Perhaps a message to the effect of "These messages are specifically disowned
by the groups to which they are posted, have historically been riddled with
blatant errors, and are assumed to continue in the same quality." should be
posted as a follow-up to each of these messages by XL in order to avoid
having to spend the time to find the inaccuracies in each one individually.

Considering the response so far, a list of frequent posters and
not-so-frequent posters who will vouch for the accuracy of the disclaimer
might even be added.

Daniel Fackrell

Jul 18 '05 #2
Perhaps someone will write a program to automatically follow up on every
[perl-python] posting? The follow-up could just contain a statement like
the one Daniel mentions. Obviously the program would be written in python.
;-)

Any suggestions on how to implement such a program? How would it detect a
new posting? How would it send the follow-up?

Anyway, I agree with Daniel and I think that would not only warn newcomers
to the group, but it would also allow many of us to move on without worrying
about the effect that the perl-python postings may have on these newcomers.

BTW, I think Daniel's suggestion for the statement sounds pretty fair and
pretty impartial. Maybe it should just not use terms like "blatant". And I
would include something like "we support everyone's freedom to post to this
newsgroup but we feel that python and perl beginners need to be warned about
the quality of these tutorials".

Dan

"Daniel Fackrell" <un*******@gmail.com> wrote in message
news:ma***************************************@pyt hon.org...
Perhaps a message to the effect of "These messages are specifically
disowned
by the groups to which they are posted, have historically been riddled
with
blatant errors, and are assumed to continue in the same quality." should
be
posted as a follow-up to each of these messages by XL in order to avoid
having to spend the time to find the inaccuracies in each one
individually.

Considering the response so far, a list of frequent posters and
not-so-frequent posters who will vouch for the accuracy of the disclaimer
might even be added.

Daniel Fackrell

Jul 18 '05 #3
Dan Perl wrote:
Perhaps someone will write a program to automatically follow up on every
[perl-python] posting? The follow-up could just contain a statement like
the one Daniel mentions. Obviously the program would be written in python.
;-)


I'm not really sure that such a disclaimer is explicitly necessary.
Anyone looking at Xah Lee's posts will also see the threads they
generate, which involve people pointing out all their errors. Granted
this won't happen with every single post, but since he's posting this
stuff once a day, I don't think the chances of someone finding his posts
and not seeing the related discussion and refutations is a big risk.

For the rest of us, we can just killfile the threads easily enough.

--
Erik Max Francis && ma*@alcyone.com && http://www.alcyone.com/max/
San Jose, CA, USA && 37 20 N 121 53 W && AIM erikmaxfrancis
Little things / Cut like knives / Hurt and sting
-- Anggun
Jul 18 '05 #4
On Tue, 1 Feb 2005 18:59:18 -0500, Dan Perl <da*****@rogers.com> wrote:
Perhaps someone will write a program to automatically follow up on every
[perl-python] posting? The follow-up could just contain a statement like
the one Daniel mentions. Obviously the program would be written in python.
;-)

Any suggestions on how to implement such a program? How would it detect a
new posting? How would it send the follow-up?

Anyway, I agree with Daniel and I think that would not only warn newcomers
to the group, but it would also allow many of us to move on without worrying
about the effect that the perl-python postings may have on these newcomers.


I'd just like the py*********@python.org mailing list to drop his
posts on the floor so I don't have to read them.

But thats me.

Stephen.
Jul 18 '05 #5
>>>>> Stephen Thorne <st************@gmail.com> writes:
On Tue, 1 Feb 2005 18:59:18 -0500, Dan Perl <da*****@rogers.com> wrote:
Perhaps someone will write a program to automatically follow up
on every [perl-python] posting? The follow-up could just
contain a statement like the one Daniel mentions. Obviously
the program would be written in python. ;-)

Any suggestions on how to implement such a program? How would
it detect a new posting? How would it send the follow-up?

Anyway, I agree with Daniel and I think that would not only
warn newcomers to the group, but it would also allow many of us
to move on without worrying about the effect that the
perl-python postings may have on these newcomers.
I'd just like the py*********@python.org mailing list to drop
his posts on the floor so I don't have to read them. But thats me. Stephen.


Falls into the 'cure worse than the disease' category.
It's really just a prompt to explore the corners of Gnus, and
determine how to give X.L. the thorough ignoring he deserves.
R,
C
Jul 18 '05 #6
On Tue, 01 Feb 2005 21:19:34 -0500, Chris Smith
<sm*************@bigfoot.com> wrote:
Falls into the 'cure worse than the disease' category.
It's really just a prompt to explore the corners of Gnus, and
determine how to give X.L. the thorough ignoring he deserves.


*headdesk*

I'm using gmail, and I can set up the filter trivially
(from:xa*@xahlee.org -> delete), but I just wasn't thinking clearly. I
was cursing not having the ability to use a procmail filter while the
solution was right in front of me.

Regards,
Stephen.
Jul 18 '05 #7
- Henry Wadsworth Longfellow
"Erik Max Francis" <ma*@alcyone.com> wrote in message
news:fb********************@speakeasy.net...
Dan Perl wrote:
Perhaps someone will write a program to automatically follow up on every
[perl-python] posting? The follow-up could just contain a statement like the one Daniel mentions. Obviously the program would be written in python. ;-)


I'm not really sure that such a disclaimer is explicitly necessary.
Anyone looking at Xah Lee's posts will also see the threads they
generate, which involve people pointing out all their errors. Granted
this won't happen with every single post, but since he's posting this
stuff once a day, I don't think the chances of someone finding his posts
and not seeing the related discussion and refutations is a big risk.

For the rest of us, we can just killfile the threads easily enough.


It seems to me that application of one of these solutions reduces the
effectiveness of the other. If enough persons killfile the threads, who
warns the newbies? And so those who don't killfile the threads to ensure
that somebody is still guarding against misleading information to newbies
continue dealing with it manually.

Daniel Fackrell

Jul 18 '05 #8
Daniel Fackrell wrote:
It seems to me that application of one of these solutions reduces the
effectiveness of the other. If enough persons killfile the threads, who
warns the newbies? And so those who don't killfile the threads to ensure
that somebody is still guarding against misleading information to newbies
continue dealing with it manually.


My point was, a sufficiently persistent pest will always generate enough
dissatisfaction to get people pointing out his uselessness. Even when
others killfile him, there will be those that stick around to point out
his foolishness to others, including any newbies who might otherwise
conclude that Xah Lee knows what the hell he's talking about.

And, in fact, that's exactly what we're seeing. It just seems to me
that any further institutionalization of criticism of Xah Lee's posts is
unnecessary; it's already being handled, at low levels of annoyance that
can be avoided by anyone with a killfile or mail filter.

--
Erik Max Francis && ma*@alcyone.com && http://www.alcyone.com/max/
San Jose, CA, USA && 37 20 N 121 53 W && AIM erikmaxfrancis
Divorces are made in Heaven.
-- Oscar Wilde
Jul 18 '05 #9
>>>>> Stephen Thorne <st************@gmail.com> writes:
On Tue, 01 Feb 2005 21:19:34 -0500, Chris Smith
<sm*************@bigfoot.com> wrote:
Falls into the 'cure worse than the disease' category. It's
really just a prompt to explore the corners of Gnus, and
determine how to give X.L. the thorough ignoring he deserves.
*headdesk* I'm using gmail, and I can set up the filter trivially
(from:xa*@xahlee.org -> delete), but I just wasn't thinking
clearly. I was cursing not having the ability to use a procmail
filter while the solution was right in front of me. Regards, Stephen.


There, there, friend; we've all reached for the Big, Fancy Hammer
(BFH) when there was a lazier way to do it. ;)
Best,
Chris
Jul 18 '05 #10

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

Similar topics

4
by: Mark Wilson CPU | last post by:
This must be easy, but I'm missing something... I want to execute a Perl script, and capture ALL its output into a PHP variable. Here are my 2 files: -------------------------------------...
6
by: John Smith | last post by:
Hello, I have a rather odd question. My company is an all java/oracle shop. We do everything is Java... no matter what it is... parsing of text files, messaging, gui you name it. My question...
3
by: David F. Skoll | last post by:
Hi, I'm tearing my hair out on this one. I'm trying to embed a Perl interpreter into a C program. I need to be able to create and destroy the interpreter periodically, but will never actually...
1
by: Julia Bell | last post by:
I would like to run the same script on two different platforms. The directory in which the script(s) will be stored is common to the two platforms. (I see the same directory contents regardless...
1
by: smsabu2002 | last post by:
Hi, I am facing the build problem while installing the DBD-MySql perl module (ver 2.9008) using both GCC and CC compilers in HP-UX machine. For the Build using GCC, the compiler error is...
13
by: Otto J. Makela | last post by:
I'm trying to install to php the Perl-1.0.0.tgz package (from http://pecl.php.net/package/perl, enabling one to call perl libraries) to a pre-existing Solaris system. Unfortunately, the attempt...
6
by: surfivor | last post by:
I may be involved in a data migration project involving databases and creating XML feeds. Our site is PHP based, so I imagine the team might suggest PHP, but I had a look at the PHP documentation...
4
by: billb | last post by:
I installed a perl extension for PHP to use some perl inside my php primarily because I have perl working with oracle and not php and oracle. So I want to use my old perl scripts, and use the...
21
KevinADC
by: KevinADC | last post by:
Note: You may skip to the end of the article if all you want is the perl code. Introduction Uploading files from a local computer to a remote web server has many useful purposes, the most...
3
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 3 Jan 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). For other local times, please check World Time Buddy In...
0
by: jianzs | last post by:
Introduction Cloud-native applications are conventionally identified as those designed and nurtured on cloud infrastructure. Such applications, rooted in cloud technologies, skillfully benefit from...
0
by: abbasky | last post by:
### Vandf component communication method one: data sharing ​ Vandf components can achieve data exchange through data sharing, state sharing, events, and other methods. Vandf's data exchange method...
0
by: stefan129 | last post by:
Hey forum members, I'm exploring options for SSL certificates for multiple domains. Has anyone had experience with multi-domain SSL certificates? Any recommendations on reliable providers or specific...
0
Git
by: egorbl4 | last post by:
Скачал я git, хотел начать настройку, а там вылезло вот это Что это? Что мне с этим делать? ...
1
by: davi5007 | last post by:
Hi, Basically, I am trying to automate a field named TraceabilityNo into a web page from an access form. I've got the serial held in the variable strSearchString. How can I get this into the...
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: Aftab Ahmad | last post by:
So, I have written a code for a cmd called "Send WhatsApp Message" to open and send WhatsApp messaage. The code is given below. Dim IE As Object Set IE =...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...

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.