473,386 Members | 1,745 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.

Regular Expression Query

Hi,

I'm studying perl programming now. Previously I encountered a script
with 3 statements as below.

# space between a +, - or " char b4 a keyword? remove it!
$in{keywords}=~s/ \+ +/ \+/g;
$in{keywords}=~s/ \- +/ \-/g;
$in{keywords}=~s/ \" +/ \"/g;

I would like to ask how the regexps function as the comment describe ?

Thanks!
Jul 19 '05 #1
1 1773
lo*************@my-deja.com (lonelyplanet999) wrote in message news:<2c**************************@posting.google. com>...
Subject: Regular Expression Query
Poor subject line.

See http://www.cpan.org/authors/id/D/DM/DMR/subjects.post
# space between a +, - or " char b4 a keyword? remove it!
$in{keywords}=~s/ \+ +/ \+/g;
$in{keywords}=~s/ \- +/ \-/g;
$in{keywords}=~s/ \" +/ \"/g;

I would like to ask how the regexps function as the comment describe ?


They do not. The contstraint "before a keyword" is not in there.

Lets just look at one:

s/ \- +/ \-/g;

The backslashes are redundant, hyphen is not meta in string or regex.

s/search/relpace/g means replace as many non-overlapping matches for
the pattern /search/ with the string replace.

The pattern / - +/ matches a space, followed by a hyphen followed by
one or more spaces.

The string " -" is, err..., the string " -".

BTW the =~ binding operator is used to specify the variable on which
s/// is to act.

That's all there is to it.

No capturing, no interpolation, no subtlties. This really is about
the simplest s/// example you could imagine.

If you are at the stage where you have many questions at this level
then you probably are not at the stage where asking questions in
newsgroups is an effective use of your time or other people's. You
should probably be working through some basic Perl tutorials.

Actually, assuming this is someone else's code, it would appear that
the person who wrote it is not much further advanced. Anyone who had
even basic competance in Perl would usually combine these into a
single s///g

s/( [-+"]) +/$1/g;

As I said before attempting to learn Perl programming from this code
is not a good idea.

I have already pointed out to you that this newsgroup does not exist.
Really, it doesn't (it only appears to exist on misconfigured news
servers). For further explaination please see the FAQ. Please do not
start any more threads here.
Jul 19 '05 #2

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

Similar topics

1
by: Kenneth McDonald | last post by:
I'm working on the 0.8 release of my 'rex' module, and would appreciate feedback, suggestions, and criticism as I work towards finalizing the API and feature sets. rex is a module intended to make...
4
by: Együd Csaba | last post by:
Hi All, I'd like to "compress" the following two filter expressions into one - assuming that it makes sense regarding query execution performance. .... where (adate LIKE "2004.01.10 __:30" or...
7
by: Billa | last post by:
Hi, I am replaceing a big string using different regular expressions (see some example at the end of the message). The problem is whenever I apply a "replace" it makes a new copy of string and I...
25
by: Mike | last post by:
I have a regular expression (^(.+)(?=\s*).*\1 ) that results in matches. I would like to get what the actual regular expression is. In other words, when I apply ^(.+)(?=\s*).*\1 to " HEART...
2
by: comp.lang.php | last post by:
I am trying to replace within the HTML string $html the following: With Where I'm replacing "action=move_image" with "action=<?= $_REQUEST ?>"
6
by: rorymo | last post by:
I have a regular expression that allows only certain characters to be valid in an xml doc as follows: <xs:pattern value="^*" /> What I want to do is also allow any unicode character that is...
1
by: Allan Ebdrup | last post by:
I have a dynamic list of regular expressions, the expressions don't change very often but they can change. And I have a single string that I want to match the regular expressions against and find...
4
by: Brian Simmons | last post by:
Hi All, I've got a textbox where I want to make sure the person has entered at least 3 characters before submitting (it's like a partial name lookup type of query), so I don't want them to just...
8
by: Nicodemas | last post by:
Hello all, could not find a regular expression forum, so I thought I would post it to my favorite of the forums. I have a series of applications I've developed which all use a centralized...
10
by: Julien | last post by:
Hi, I'm fairly new in Python and I haven't used the regular expressions enough to be able to achieve what I want. I'd like to select terms in a string, so I can then do a search in my database....
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
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
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?
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
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
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...

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.