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

Regexp question

I realize this is more a regexp question than a python question, but maybe one
of the re object could help me:

I have wish to know how to _no_ match:

This is but an example of the data I handle:

xx xx xx xx xx xx xx [yy yy yy yy yy yy yy] (zz zz zz zz)

I currently can retrieve the three group of logical data blocks with:

l_str = 'xx xx xx xx xx xx xx [yy yy yy yy yy yy yy] (zz zz zz zz)'
p = re.compile(r'([a-f-0-9\s]*) (\[[a-f-0-9\s]*\])
(\([a-f-0-9\s]*\))',re.IGNORECASE) #OK
g = p.search(l_str)
What I would rather do is.

"get the data block that is _not_ between brackets or parenthesis i.e; 'xx xx
xx xx xx xx xx' knowing that the intial string could be:

[yy yy yy yy yy yy yy] xx xx xx xx xx xx xx (zz zz zz zz)
Any clue ?

Regards,

Philippe


--
*********************
Philippe C. Martin
SnakeCard LLC
www.snakecard.com
*********************
Jul 18 '05 #1
1 1104
On Wed, 1 Dec 2004 07:48:24 -0600, Philippe C. Martin
<ph*************@sbcglobal.net> wrote:
I realize this is more a regexp question than a python question, but
maybe one
of the re object could help me:

I have wish to know how to _no_ match:

This is but an example of the data I handle:

xx xx xx xx xx xx xx [yy yy yy yy yy yy yy] (zz zz zz zz)

I currently can retrieve the three group of logical data blocks with:

l_str = 'xx xx xx xx xx xx xx [yy yy yy yy yy yy yy] (zz zz zz zz)'
p = re.compile(r'([a-f-0-9\s]*) (\[[a-f-0-9\s]*\])
(\([a-f-0-9\s]*\))',re.IGNORECASE) #OK
g = p.search(l_str)
What I would rather do is.

"get the data block that is _not_ between brackets or parenthesis i.e;
'xx xx
xx xx xx xx xx' knowing that the intial string could be:

[yy yy yy yy yy yy yy] xx xx xx xx xx xx xx (zz zz zz zz)
Any clue ?


regexps seem an overkill for the task at hand.

If data is really as simple as you suggest, you can try the following:
s = 'xx [y y] (z z)'
s = s[:s.index('(')] + s[s.index(')')+1:]
s 'xx [y y] ' s = s[:s.index('[')] + s[s.index(']')+1:]
s 'xx ' s.strip()

'xx'
Relevant lines:
s = s[:s.index('(')] + s[s.index(')'):]
s = s[:s.index('[')] + s[s.index(']')+1:]
s = s.strip()
--
Mitja
Jul 18 '05 #2

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

Similar topics

1
by: python_charmer2000 | last post by:
I want to match several regexps against a large body of text. What I have so far is similar to this: re1 = <some regexp> re2 = <some regexp> re3 = <some regexp> big_re = re.compile(re1 +...
19
by: Magnus Lie Hetland | last post by:
I'm working on a project (Atox) where I need to match quite a few regular expressions (several hundred) in reasonably large text files. I've found that this can easily get rather slow. (There are...
5
by: Lukas Holcik | last post by:
Hi everyone! How can I simply search text for regexps (lets say <a href="(.*?)">(.*?)</a>) and save all URLs(1) and link contents(2) in a dictionary { name : URL}? In a single pass if it could....
4
by: Jon Maz | last post by:
Hi All, I want to strip the accents off characters in a string so that, for example, the (Spanish) word "práctico" comes out as "practico" - but ignoring case, so that "PRÁCTICO" comes out as...
3
by: Sped Erstad | last post by:
There must be a simple regexp reason for this little question but it's driving me nuts. Below is a simple regexp to determine if a string contains only numbers. I'm running these two strings...
2
by: Bill McCormick | last post by:
Hello, I'm new to VB.NET but have used regexp in Perl and VI. I'd like to read a regular expression from a file and apply it to a string read from another file. The regexp is simple word...
26
by: Matt Kruse | last post by:
Are there any current browsers that have Javascript support, but not RegExp support? For example, cell phone browsers, blackberrys, or other "minimal" browsers? I know that someone using Netscape...
7
by: Csaba Gabor | last post by:
I need to come up with a function function regExpPos (text, re, parenNum) { ... } that will return the position within text of RegExp.$parenNum if there is a match, and -1 otherwise. For...
11
by: HopfZ | last post by:
I coudn't understand some behavior of RegExp.test function. Example html code: ---------------- <html><head></head><body><script type="text/javascript"> var r = /^https?:\/\//g;...
8
by: Darryl Kerkeslager | last post by:
Currently I am using the RegExp object to parse a large dataset in an Access table - but this table was exported from SQL Server, and the very correct question was asked - why not just do it in SQL...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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,...
0
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...
0
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...
0
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...

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.