re.search

R

Rares Vernica

Hi,

Isn't the following code supposed to return ('1994')?
(None,)

Thanks,
Ray
 
J

James Stroud

Rares said:
Hi,

Isn't the following code supposed to return ('1994')?

(None,)

Thanks,
Ray

The ? is allowing it to not match before it finds the 1994.

Note:

py> re.search('(\d{4})?', '1994 4').groups()
('1994',)

James

--
James Stroud
UCLA-DOE Institute for Genomics and Proteomics
Box 951570
Los Angeles, CA 90095

http://www.jamesstroud.com/
 
F

Fredrik Lundh

Rares said:
Isn't the following code supposed to return ('1994')?

(None,)

it's supposed to return the first thing that matches your pattern, which,
in this case, is the empty string at the beginning of the target string.

if you want to look for groups of four digits, remove the "?"

</F>
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,289
Messages
2,571,435
Members
48,120
Latest member
Natbelix

Latest Threads

Top