473,403 Members | 2,354 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,403 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 1944
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> <head><title>Hello, World</title></head> <body...
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 seen the contracts for Python:...
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 text inside single or double quotes? For making...
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 a frustrating bit of time figuring out why pydoc...
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 question is that since a triple quoted string is...
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 infomation. The string I have is below. ...
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 that found sub-string is inside single-quotes or...
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 's/\.htm$/\.html/' *.htm it works fine... however when I...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

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.