Connecting Tech Pros Worldwide Forums | Help | Site Map

Regexp question

Philippe C. Martin
Guest
 
Posts: n/a
#1: Jul 18 '05
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
*********************
Mitja
Guest
 
Posts: n/a
#2: Jul 18 '05

re: Regexp question


On Wed, 1 Dec 2004 07:48:24 -0600, Philippe C. Martin
<philippecmartin@sbcglobal.net> wrote:
[color=blue]
> 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 ?[/color]

regexps seem an overkill for the task at hand.

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


Relevant lines:
s = s[:s.index('(')] + s[s.index(')'):]
s = s[:s.index('[')] + s[s.index(']')+1:]
s = s.strip()
--
Mitja
Closed Thread


Similar Python bytes