Connecting Tech Pros Worldwide Forums | Help | Site Map

Negative regular expressions (searching for "i" not inside command)

Bart Kastermans
Guest
 
Posts: n/a
#1: Aug 28 '08
I have a file in which I am searching for the letter "i" (actually
a bit more general than that, arbitrary regular expressions could
occur) as long as it does not occur inside an expression that matches
\\.+?\b (something started by a backslash and including the word that
follows).

More concrete example, I have the string "\sin(i)" and I want to match
the argument, but not the i in \sin.

Can this be achieved by combining the regular expressions? I do not
know the right terminology involved, therefore my searching on the
Internet has not led to any results.

I can achieve something like this by searching for all i and then
throwing away those i that are inside such expressions. I am now just
wondering if these two steps can be combined into one.

Best,
Bart
--
http://www.bartk.nl/

Guilherme Polo
Guest
 
Posts: n/a
#2: Aug 28 '08

re: Negative regular expressions (searching for "i" not inside command)


On Thu, Aug 28, 2008 at 5:04 PM, Bart Kastermans
<kasterma@math.wisc.edu${hostname}wrote:
Quote:
I have a file in which I am searching for the letter "i" (actually
a bit more general than that, arbitrary regular expressions could
occur) as long as it does not occur inside an expression that matches
\\.+?\b (something started by a backslash and including the word that
follows).
>
More concrete example, I have the string "\sin(i)" and I want to match
the argument, but not the i in \sin.
>
Can this be achieved by combining the regular expressions? I do not
know the right terminology involved, therefore my searching on the
Internet has not led to any results.
Try searching again with the "lookahead" term, or "negative lookahead".
Quote:
>
I can achieve something like this by searching for all i and then
throwing away those i that are inside such expressions. I am now just
wondering if these two steps can be combined into one.
>
Best,
Bart
--
http://www.bartk.nl/
--
http://mail.python.org/mailman/listinfo/python-list
>


--
-- Guilherme H. Polo Goncalves
castironpi
Guest
 
Posts: n/a
#3: Aug 28 '08

re: Negative regular expressions (searching for "i" not inside command)


On Aug 28, 4:04*pm, "Guilherme Polo" <ggp...@gmail.comwrote:
Quote:
On Thu, Aug 28, 2008 at 5:04 PM, Bart Kastermans
>
<kaste...@math.wisc.edu${hostname}wrote:
Quote:
I have a file in which I am searching for the letter "i" (actually
a bit more general than that, arbitrary regular expressions could
occur) as long as it does not occur inside an expression that matches
\\.+?\b (something started by a backslash and including the word that
follows).
>
Quote:
More concrete example, I have the string "\sin(i)" and I want to match
the argument, but not the i in \sin.
>
Quote:
Can this be achieved by combining the regular expressions? *I do not
know the right terminology involved, therefore my searching on the
Internet has not led to any results.
>
Try searching again with the "lookahead" term, or "negative lookahead".
>
>
>
Quote:
I can achieve something like this by searching for all i and then
throwing away those i that are inside such expressions. *I am now just
wondering if these two steps can be combined into one.
>>
--
-- Guilherme H. Polo Goncalves
No dice: "This is called a positive lookbehind assertion. ...The
contained pattern must only match strings of some fixed length."
'finditer' could make the 'combined into one' option more attractive
though.
Closed Thread