Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > Regexp question

Reply
Thread Tools

Regexp question

 
 
Philippe C. Martin
Guest
Posts: n/a
 
      12-01-2004
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
*********************
 
Reply With Quote
 
 
 
 
Mitja
Guest
Posts: n/a
 
      12-01-2004
On Wed, 1 Dec 2004 07:48:24 -0600, Philippe C. Martin
<(E-Mail Removed)> 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
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
new RegExp().test() or just RegExp().test() Matěj Cepl Javascript 3 11-24-2009 02:41 PM
[regexp] How to convert string "/regexp/i" to /regexp/i - ? Joao Silva Ruby 16 08-21-2009 05:52 PM
Ruby 1.9 - ArgumentError: incompatible encoding regexp match(US-ASCII regexp with ISO-2022-JP string) Mikel Lindsaar Ruby 0 03-31-2008 10:27 AM
Programmatically turning a Regexp into an anchored Regexp Greg Hurrell Ruby 4 02-14-2007 06:56 PM
RegExp.exec() returns null when there is a match - a JavaScript RegExp bug? Uldis Bojars Javascript 2 12-17-2006 09:59 PM



Advertisments