472,333 Members | 1,024 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,333 software developers and data experts.

quotes at the edges of a triple quote string...

property = re.compile("""(?P<name>[a-z0-9_\-]+)="(?P<value>.*?)""""re.I)

This doesn't work because the closing quote in my regex forms the first
quote of a triple quote to end the string...

property = re.compile("""(?P<name>[a-z0-9_\-]+)=("(?P<value>.*?)")""", re.I)

This mucks up stuff I want to do later.

I've thought about it for a while, and except for changing it to a
single-quoted string with escaped quotes, is there any clean way to do this?

TIA,
Anthony
Jul 18 '05 #1
3 1876
Anthony Roberts wrote:
property = re.compile("""(?P<name>[a-z0-9_\-]+)="(?P<value>.*?)""""re.I)

This doesn't work because the closing quote in my regex forms the first
quote of a triple quote to end the string...

property = re.compile("""(?P<name>[a-z0-9_\-]+)=("(?P<value>.*?)")""",
re.I)

This mucks up stuff I want to do later.

I've thought about it for a while, and except for changing it to a
single-quoted string with escaped quotes, is there any clean way to do
this?


Can't you still use a triple-quoted string, but escape the
last quote?
"""test\""""

'test"'

-Peter
Jul 18 '05 #2
> Can't you still use a triple-quoted string, but escape the
last quote?
>>> """test\"""" 'test"'


Yes... yes I can. I can also use the other quotetation marks. I realized
this just after I posted.
'''test"'''

'test"'

Either way works.

Thank you for the quick response. :)
Jul 18 '05 #3
Anthony Roberts wrote (looking to fix):
prop = re.compile("""(?P<name>[a-z0-9_\-]+)="(?P<value>.*?)""""re.I)
Peter Hansen wrote:
Can't you still use a triple-quoted string, but escape the
last quote?
>>> """test\""""
Yes... yes I can. I can also use the other quotetation marks. I realized
this just after I posted.
>>> '''test"'''

'test"'


A couple of things to realize (esp if you are getting into longer regexps).

1) r"""abc""" is a raw string with a triple quote.
2) Also, 'abc' 'def' (string splicing) is _exactly_ the same as 'abcdef'
The separate strings are glued together when converting the code to
bytecode, so there is no cost of concatenation to worry about.

What you might use for a regexp, then might be:

prop = re.compile(r"(?P<name>[a-z0-9_\-]+)="
r'"(?P<value>.*?)"')

The argument parens are enough for grouping, and the expression
broken at appropriate points is arguably more readable.

-Scott
Jul 18 '05 #4

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

Similar topics

8
by: Christoph Zwerschke | last post by:
I sometimes use triple quotes in order to produce snippets of multiline code, like that: if output == html: snip = '''<html>...
11
by: bearophile | last post by:
Hello, here are a four more questions (or suggestions) for the language (probably people have already discussed some of/all such things: I've...
4
by: beliavsky | last post by:
The code for text in open("file.txt","r"): print text.replace("foo","bar") replaces 'foo' with 'bar' in a file, but how do I avoid changing...
7
by: Brian van den Broek | last post by:
Hi all, I'm posting partly so my problem and solution might be more easily found by google, and partly out of mere curiosity. I've just spent...
3
by: Michele Simionato | last post by:
I am getting trouble with nested triple quoted strings in doctest. For instance $ cat x.py """ >>> dummy = ''' something here ''' """
14
by: dmh2000 | last post by:
I recently complained elsewhere that Python doesn't have multiline comments. i was told to use triple quoted strings to make multiline comments. My...
1
by: veaux | last post by:
I'm using Access query and have to spit out a text file to load into a 3rd party program. The text file has to include quotes (" ") around certain...
4
by: Michael Yanowitz | last post by:
Hello: If I have a long string (such as a Python file). I search for a sub-string in that string and find it. Is there a way to determine if...
7
by: skunkwerk | last post by:
Hi, i'm trying to call subprocess.popen on the 'rename' function in linux. When I run the command from the shell, like so: rename -vn...
0
better678
by: better678 | last post by:
Question: Discuss your understanding of the Java platform. Is the statement "Java is interpreted" correct? Answer: Java is an object-oriented...
0
by: teenabhardwaj | last post by:
How would one discover a valid source for learning news, comfort, and help for engineering designs? Covering through piles of books takes a lot of...
0
by: Kemmylinns12 | last post by:
Blockchain technology has emerged as a transformative force in the business world, offering unprecedented opportunities for innovation and...
0
by: CD Tom | last post by:
This only shows up in access runtime. When a user select a report from my report menu when they close the report they get a menu I've called Add-ins...
0
by: Naresh1 | last post by:
What is WebLogic Admin Training? WebLogic Admin Training is a specialized program designed to equip individuals with the skills and knowledge...
0
by: antdb | last post by:
Ⅰ. Advantage of AntDB: hyper-convergence + streaming processing engine In the overall architecture, a new "hyper-convergence" concept was...
0
by: Matthew3360 | last post by:
Hi there. I have been struggling to find out how to use a variable as my location in my header redirect function. Here is my code. ...
2
by: Matthew3360 | last post by:
Hi, I have a python app that i want to be able to get variables from a php page on my webserver. My python app is on my computer. How would I make it...
0
hi
by: WisdomUfot | last post by:
It's an interesting question you've got about how Gmail hides the HTTP referrer when a link in an email is clicked. While I don't have the specific...

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.