Python regex

A

Andrew Rekdal

I hope posting is ok here for this question...

I am attempting to extract the text from a CSS comment using 're' such as...

string = "/* CSS comment /*"
exp = "[^(/*)].*[^(*/)] "

p = re.compile(exp)
q = p.search(string)
r = q.group()

print r

although this works to a degree... I know the within the brackets everything
is taken literally so the pattern
I am to negating is "(/*)". ie. includes the parenthesis.

So my question is...

Is there a way to negate a pattern that is more than on character long? eg.
where rather than saying if forward slash OR astrisk appear..negate.

I would be saying if parenthesis AND asterisk appear in this order... negate


-- Andrew
 
A

Andrew Rekdal

made error on last line... read as...
I would be saying if forward-slash AND asterisk appear in this order...
negate


--
-- Andrew

Andrew Rekdal @comcast.net> said:
I hope posting is ok here for this question...

I am attempting to extract the text from a CSS comment using 're' such
as...

string = "/* CSS comment /*"
exp = "[^(/*)].*[^(*/)] "

p = re.compile(exp)
q = p.search(string)
r = q.group()

print r

although this works to a degree... I know the within the brackets
everything is taken literally so the pattern
I am to negating is "(/*)". ie. includes the parenthesis.

So my question is...

Is there a way to negate a pattern that is more than on character long?
eg. where rather than saying if forward slash OR astrisk appear..negate.

I would be saying if parenthesis AND asterisk appear in this order...
negate


-- Andrew
 
A

Arnaud Delobelle

I hope posting is ok here for this question...

I am attempting to extract the text from a CSS comment using 're' such as....

string = "/* CSS comment /*"
exp = "[^(/*)].*[^(*/)] "

p = re.compile(exp)
q = p.search(string)
r = q.group()

print r

although this works to a degree... I know the within the brackets everything
is taken literally so the pattern
I am to negating is "(/*)". ie. includes the parenthesis.

So my question is...

Is there a way to negate a pattern that is more than on character long? eg..
where rather than saying if forward slash OR astrisk appear..negate.

I would be saying if parenthesis AND asterisk appear in this order... negate

-- Andrew

There would be many ways to do this. One:

HTH
 
A

Andrew Rekdal

--
-- Andrew

I hope posting is ok here for this question...

I am attempting to extract the text from a CSS comment using 're' such
as...

string = "/* CSS comment /*"
exp = "[^(/*)].*[^(*/)] "

p = re.compile(exp)
q = p.search(string)
r = q.group()

print r

although this works to a degree... I know the within the brackets
everything
is taken literally so the pattern
I am to negating is "(/*)". ie. includes the parenthesis.

So my question is...

Is there a way to negate a pattern that is more than on character long?
eg.
where rather than saying if forward slash OR astrisk appear..negate.

I would be saying if parenthesis AND asterisk appear in this order...
negate

-- Andrew

There would be many ways to do this. One:

HTH

--
Arnaud

Arnaud,

in your expression above..

what does the 'r' do?

-- andrew
 
A

Adonis Vargas

Andrew said:
I hope posting is ok here for this question...

I am attempting to extract the text from a CSS comment using 're' such as...

string = "/* CSS comment /*"
exp = "[^(/*)].*[^(*/)] "

p = re.compile(exp)
q = p.search(string)
r = q.group()

print r

although this works to a degree... I know the within the brackets everything
is taken literally so the pattern
I am to negating is "(/*)". ie. includes the parenthesis.

So my question is...

Is there a way to negate a pattern that is more than on character long? eg.
where rather than saying if forward slash OR astrisk appear..negate.

I would be saying if parenthesis AND asterisk appear in this order... negate


-- Andrew

Have you looked into this library:

http://cthedot.de/cssutils/

May help you, if you are trying to achieve something. If your doing it
as an exercise then I can not help you, I avoid regex like the plague
(but thats just me).

Hope this helps.

Adonis Vargas
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top