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

regular expression questions in Python

I am (very) new top regular expressions and I am having a difficult time
understanding how to do them. I have the following in my script:

zaidsearch = r'''^ {5,}([\d]{4,5})(.\d{2,2}c)'''
ZAIDSearch = re.compile(search, re.IGNORECASE)

When I do: ZAID.search(...) then this works fine. I would like to write
it as:

zaidsearch = r'''^ {5,}([\d]{4,5}) #My comments
(.\d{2,2}c) #More of my comments'''
ZAIDSearch = re.compile(zaidsearch, re.VERBOSE)

but this doesn't work. I get the following error:

raise error, v # invalid expression
sre_constants.error: nothing to repeat
So I guess my question is: how do I use the VERBOSE option to make my
regular expression easier to understand for a human? Secondly, how can
I use both the VERBOSE and IGNORECASE options?
Thanks,
Jeremy

Jul 21 '05 #1
1 1352
Jeremy wrote:
I am (very) new top regular expressions and I am having a difficult time
understanding how to do them. I have the following in my script:

zaidsearch = r'''^ {5,}([\d]{4,5})(.\d{2,2}c)'''
ZAIDSearch = re.compile(search, re.IGNORECASE)

When I do: ZAID.search(...) then this works fine. I would like to write
it as:

zaidsearch = r'''^ {5,}([\d]{4,5}) #My comments ^ This space will not be a space in the RE.
You have to specify a space with '[ ]' or '\ '
when using re.VERBOSE
(.\d{2,2}c) #More of my comments'''
ZAIDSearch = re.compile(zaidsearch, re.VERBOSE)

but this doesn't work. I get the following error:

raise error, v # invalid expression
sre_constants.error: nothing to repeat

Reinhold
Jul 21 '05 #2

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

Similar topics

6
by: Tony C | last post by:
I'm writing a python program which uses regular expressions, but I'm totally new to regexps. I've got Kuchling's "Regexp HOWTO", "Mastering Regular Expresions" by Oreilly, and have access to...
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...
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...
5
by: Avi Kak | last post by:
Folks, Does regular expression processing in Python allow for executable code to be embedded inside a regular expression? For example, in Perl the following two statements $regex =...
8
by: Uwe Schmitt | last post by:
Hi, Is anobody aware of this post: http://swtch.com/~rsc/regexp/regexp1.html ? Are there any plans to speed up Pythons regular expression module ? Or is the example in this artricle too...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
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: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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...

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.