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

REGULAR EXPRESSION

hi.. I am trying to match '+ %&/-' etc using regular expression in
expressions like 879+34343. I tried \W+ but it matches only in the
beginning of the string Plz help Thanking you in advance...

Sep 4 '07 #1
7 1048
AniNair wrote:
hi.. I am trying to match '+ %&/-' etc using regular expression in
expressions like 879+34343. I tried \W+ but it matches only in the
beginning of the string Plz help Thanking you in advance...
Perhaps you could give a few example of strings that should and
shouldn't match? It isn't clear from your description what pattern you
are trying to find.

regards
Steve
--
Steve Holden +1 571 484 6266 +1 800 494 3119
Holden Web LLC/Ltd http://www.holdenweb.com
Skype: holdenweb http://del.icio.us/steve.holden
--------------- Asciimercial ------------------
Get on the web: Blog, lens and tag the Internet
Many services currently offer free registration
----------- Thank You for Reading -------------

Sep 4 '07 #2
AniNair wrote:
hi.. I am trying to match '+ %&/-' etc using regular expression in
expressions like 879+34343. I tried \W+ but it matches only in the
beginning of the string Plz help Thanking you in advance...
Is this what you are seeking for?
>>re.compile('(\+{0,1})?([0-9]+)').findall('879+34343')
[('', '879'), ('+', '34343')]

Tuomas Vesterinen
Sep 4 '07 #3
On Sep 4, 6:32 am, AniNair <anitn...@gmail.comwrote:
hi.. I am trying to match '+ %&/-' etc using regular expression in
expressions like 879+34343. I tried \W+ but it matches only in the
beginning of the string Plz help Thanking you in advance...
You may want to read the page describing the regex syntax a little
closer. http://docs.python.org/lib/re-syntax.html

\W would match anything but \w. That is, it would match spaces and
tabs as well as the weird characters. I don't think that's what you
want.

Also, don't forget to use raw strings. r"\W+" is preferred over "\W+".

Sep 4 '07 #4
Steve Holden wrote:
AniNair wrote:
>hi.. I am trying to match '+ %&/-' etc using regular expression in
expressions like 879+34343. I tried \W+ but it matches only in the
beginning of the string Plz help Thanking you in advance...
Perhaps you could give a few example of strings that should and
shouldn't match? It isn't clear from your description what pattern you
are trying to find.

regards
Steve

If it's operations between two numbers try :
r'([\d.]+?)\s*([-+/*%&])([\d.]+)'
It will give you 3 groups, first number, operation and second number
(caveat emptor).
Sep 4 '07 #5
On Sep 5, 4:35 am, Ricardo Aráoz <ricar...@gmail.comwrote:
Steve Holden wrote:
AniNair wrote:
hi.. I am trying to match '+ %&/-' etc using regular expression in
expressions like 879+34343. I tried \W+ but it matches only in the
beginning of the string Plz help Thanking you in advance...
Perhaps you could give a few example of strings that should and
shouldn't match? It isn't clear from your description what pattern you
are trying to find.
regards
Steve

If it's operations between two numbers try :
r'([\d.]+?)\s*([-+/*%&])([\d.]+)'
It will give you 3 groups, first number, operation and second number
(caveat emptor).

Hi.. Thanks alot for finding time to help a beginner like me. What I
am trying to do is validate the input i get. I just want to take
numbers and numbers only. So if the input is 23+1 or 2/3 or 9-0 or
7/0 , I want to find it using reg exp. I know there are other ways to
do this... but i thought i will try this as i need to learn reg exp. I
tried \D+ , \W+, and \D+|\W+ .. Thanks once again...

Sep 5 '07 #6
AniNair wrote:
On Sep 5, 4:35 am, Ricardo Aráoz <ricar...@gmail.comwrote:
>Steve Holden wrote:
>>AniNair wrote:
hi.. I am trying to match '+ %&/-' etc using regular expression in
expressions like 879+34343. I tried \W+ but it matches only in the
beginning of the string Plz help Thanking you in advance...
Perhaps you could give a few example of strings that should and
shouldn't match? It isn't clear from your description what pattern you
are trying to find.
regards
Steve
If it's operations between two numbers try :
r'([\d.]+?)\s*([-+/*%&])([\d.]+)'
It will give you 3 groups, first number, operation and second number
(caveat emptor).


Hi.. Thanks alot for finding time to help a beginner like me. What I
am trying to do is validate the input i get. I just want to take
numbers and numbers only. So if the input is 23+1 or 2/3 or 9-0 or
7/0 , I want to find it using reg exp. I know there are other ways to
do this... but i thought i will try this as i need to learn reg exp. I
tried \D+ , \W+, and \D+|\W+ .. Thanks once again...
Well \d will match a number and '.' inside [] will match a dot ;) so if
you want only integer numbers ([\d.]*) should be replaced with (\d+)
Only problem with the expression I sent is that it will match a number
with more than one dot.

HTH
Sep 5 '07 #7
Hi.. Thanks alot for finding time to help a beginner like me. What I
am trying to do is validate the input i get. I just want to take
numbers and numbers only. So if the input is 23+1 or 2/3 or 9-0 or
7/0 , I want to find it using reg exp. I know there are other ways to
do this... but i thought i will try this as i need to learn reg exp. I
tried \D+ , \W+, and \D+|\W+ .. Thanks once again...
--

Send a couple of strings and the output you would like from each.
Sep 5 '07 #8

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: Buddy | last post by:
Can someone please show me how to create a regular expression to do the following My text is set to MyColumn{1, 100} Test I want a regular expression that sets the text to the following...
4
by: Neri | last post by:
Some document processing program I write has to deal with documents that have headers and footers that are unnecessary for the main processing part. Therefore, I'm using a regular expression to go...
11
by: Dimitris Georgakopuolos | last post by:
Hello, I have a text file that I load up to a string. The text includes certain expression like {firstName} or {userName} that I want to match and then replace with a new expression. However,...
3
by: James D. Marshall | last post by:
The issue at hand, I believe is my comprehension of using regular expression, specially to assist in replacing the expression with other text. using regular expression (\s*) my understanding is...
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...
9
by: Pete Davis | last post by:
I'm using regular expressions to extract some data and some links from some web pages. I download the page and then I want to get a list of certain links. For building regular expressions, I use...
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...
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...
1
by: NvrBst | last post by:
I want to use the .replace() method with the regular expression /^ %VAR % =,($|&)/. The following DOESN'T replace the "^default.aspx=,($|&)" regular expression with "":...
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...
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...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
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.