473,218 Members | 1,693 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,218 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 1045
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 "":...
1
isladogs
by: isladogs | last post by:
The next online meeting of the Access Europe User Group will be on Wednesday 6 Dec 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, Mike...
0
by: VivesProcSPL | last post by:
Obviously, one of the original purposes of SQL is to make data query processing easy. The language uses many English-like terms and syntax in an effort to make it easy to learn, particularly for...
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: mar23 | last post by:
Here's the situation. I have a form called frmDiceInventory with subform called subfrmDice. The subform's control source is linked to a query called qryDiceInventory. I've been trying to pick up the...
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...
2
by: jimatqsi | last post by:
The boss wants the word "CONFIDENTIAL" overlaying certain reports. He wants it large, slanted across the page, on every page, very light gray, outlined letters, not block letters. I thought Word Art...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 7 Feb 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:30 (7.30PM). In this month's session, the creator of the excellent VBE...
0
by: fareedcanada | last post by:
Hello I am trying to split number on their count. suppose i have 121314151617 (12cnt) then number should be split like 12,13,14,15,16,17 and if 11314151617 (11cnt) then should be split like...
0
Git
by: egorbl4 | last post by:
Скачал я git, хотел начать настройку, а там вылезло вот это Что это? Что мне с этим делать? ...

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.