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 1 3356
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 This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
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...
|
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")
|
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...
|
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')
|
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
| |
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:...
|
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
--...
|
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.)...
|
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)
|
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language...
|
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...
| |
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
|
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...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes...
|
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...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
| |
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
| |