473,574 Members | 2,450 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

[import re] match or findall?

Hi everyone,
I am having a problem with the match function:

import re
string = 'abc 123456 xyz'
if re.match("\d{1, }",string):
print "Found a number" #Does not print
whereas findall works:

import re
string = 'abc 123456 xyz'
if re.findall("\d{ 1,}",string):
print "Found a number" #Actually prints

Is there a function similar to findall that will find the 1st
occurrence?
I realize match is probably that similar function but I can't get this
simple
example working, for some reason.

anyone know what's wrong?

Thanks in advance.
-gohaku
Jul 18 '05 #1
1 3361
On Sat, 3 Jul 2004 18:02:45 -0400, gohaku <go****@earthli nk.net> wrote:
Hi everyone,
I am having a problem with the match function:

import re
string = 'abc 123456 xyz'
if re.match("\d{1, }",string):
print "Found a number" #Does not print
whereas findall works:

import re
string = 'abc 123456 xyz'
if re.findall("\d{ 1,}",string):
print "Found a number" #Actually prints

Is there a function similar to findall that will find the 1st
occurrence?
I realize match is probably that similar function but I can't get this
simple
example working, for some reason.


Match only matches at the beginning of the string, which is very different from
finding the first occurance.
match = re.search("\d{1 ,}",string)
if match is not None:
print "Found a number:", match.group()

--
Sam Holden
Jul 18 '05 #2

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

Similar topics

2
1579
by: Sunit Joshi | last post by:
Hello All I have a problem here where I need to find the drive letters in a text file and replace them with another letter. Now the lines can be as long as this 6 'C:\pds\bddin64\report\mto\' 'SJOSHI' 'D:\pds\bddin64\report\format\' 'SJOSHI' with multiple entries for path; i.e. there may be 2, as above or 1 or more then 2. If I use the...
4
1643
by: ajikoe | last post by:
Hello, For example I have a string : "Halo by by by" Then I want to take and know the possition of every "by" how can I do it in python? I tried to use: p = re.compile(r"by") m = p.search("Helo by by by")
1
2211
by: bjam | last post by:
Hi, today I was able to abstract out into a separate xsl file a template that I specifically perform a call templates for, this worked with import no problem. However, when trying to do the same operation with a template that I use a match template on, IE was giving me the following error for the style sheet. Does anyone know how to import...
1
1855
by: JerryB | last post by:
Hi, I have a string like this: invalidStr = "192.168.*.1" I want to be sure I don't get a * followed by a number, i.e. I want invalidStr to be invalid. So I do: numberAfterStar = re.compile(r'\*.*\d')
32
14635
by: Licheng Fang | last post by:
Basically, the problem is this: 'do' Python's NFA regexp engine trys only the first option, and happily rests on that. There's another example: 'oneself' The Python regular expression engine doesn't exaust all the
2
2244
by: =?Utf-8?B?bWdvbnphbGVzMw==?= | last post by:
I have a List<tobject consisting of objects which in themselves consist of BindingListViews of objects. When I want to search for a object value I normally create a foreach loop and increment a counter to provide me a count. How can I refactor the same function w/o the foreach and use findall instead? faux data structure:...
1
3008
by: Nick Craig-Wood | last post by:
I've been dumping a database in a python code format (for use with Python on S60 mobile phone actually) and I've noticed that it uses absolutely tons of memory as compared to how much the data structure actually needs once it is loaded in memory. The programs below create a file (z.py) with a data structure in which looks like this --...
1
2648
by: Patrick C | last post by:
I'm importing a script that I made and it's literally take 10+mins to to run or import into PythonWin. I've put the script at the bottom. But i'm also having a problem with it. What i'm trying to do: 1.) Go the the SEC's website and look for recently filed 10-q's (that's a financial report) 2.) collect all the links for these new 10-q's 3.)...
8
5985
by: The Web President | last post by:
Dear all, this is really driving me nuts and any help would be extremely appreciated. I have a string that contains some numeric data. I want to isolate these data using re.match, as follows. bogus = "IFC(35m)" data = re.match(r'(\d+)',bogus)
0
7794
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
8040
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
8225
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
7800
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
6437
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
0
5296
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3745
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2230
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1332
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.