On 3 Sep 2023, at 18:10, Jan Erik Moström via Python-list wrote:
> I'm looking for some advice for how to write this in a clean way
Thanks for all the suggestion, I realize that I haven't written Python code in
a while. I should have remembered this myself !!! Thanks for reminding me.
= jem
--
Jan Erik Moström wrote at 2023-9-3 18:10 +0200:
>I'm looking for some advice for how to write this in a clean way
> ...
>The "problem" is that I've currently written some code that works but it uses
>global variables ... and I don't like global variables. I assume there is a
>better way to write
# Do various things that involves for info
> # that what's available in m
> replacement_text = m.group(1) + global_var1 + global_var2
> return replacement_text
>
> and the call comes here
>
> global_var1 = "bla bla"
> global_var2 =
r2 = "pff"
new_text = re.sub(im_pattern,fix_stuff,md_text)
The "problem" is that I've currently written some code that works but it uses
global variables ... and I don't like global variables. I assume there is a better way to
write this, but how?
= jem
There are tw
On 3 Sep 2023, at 19:13, MRAB via Python-list wrote:
> You could use pass an anonymous function (a lambda) to re.sub:
Of course !! Thanks.
= jem
--
https://mail.python.org/mailman/listinfo/python-list
like this:
def fix_stuff(m):
# Do various things that involves for info
# that what's available in m
replacement_text = m.group(1) + global_var1 + global_var2
return replacement_text
and the call comes here
global_var1 = "bla bla"
global_var2 = &quo
that involves for info
# that what's available in m
replacement_text = m.group(1) + global_var1 + global_var2
return replacement_text
and the call comes here
global_var1 = "bla bla"
global_var2 = "pff"
new_text = re.sub(im_pattern,fix_stuff,md_text
On 01/12/15 05:28, Jussi Piitulainen wrote:
A real solution should be aware of the actual structure of those lines,
assuming they follow some defined syntax.
I think that we are in violent agreement on this ;)
E.
--
https://mail.python.org/mailman/listinfo/python-list
that's not what the OP said they wanted to do. They said
> everything was very fixed - they did not want a general purpose human
> language text processing solution ... ;)
Language processing is not what I had in mind here. Merely this, that
there is some sort of word boundary, be i
On 30/11/15 08:51, Jussi Piitulainen wrote:
Surely the straight thing to say is:
>>> foo.replace(' CONTENT_PATH ', ' Substitute ')
'foo bar baz spam Substitute bar spam'
Not quite the same thing (but yes, with a third argument of 1, it would be).
But there was no guarantee of spaces
Erik writes:
> On 29/11/15 21:36, Mr Zaug wrote:
>> This should be simple, right?
>
> It is. And it could be even simpler if you don't bother with regexes
> at all (if your input is as fixed as you say it is):
>
> >>> foo = "foo bar baz spam CONTENT_PATH bar spam"
> >>> ' Substitute '.join(foo.spl
On 29/11/15 21:36, Mr Zaug wrote:
I need to use re.sub to replace strings in a text file.
Do you? Is there any other way?
result = re.sub(pattern, repl, string, count=0, flags=0);
I think I understand that pattern is the regex I'm searching for and
repl is the thing I want to substitut
On Sunday, November 29, 2015 at 8:12:25 PM UTC-5, Rick Johnson wrote:
> On Sunday, November 29, 2015 at 3:37:34 PM UTC-6, Mr Zaug wrote:
>
> > The items I'm searching for are few and they do not change. They are
> > "CONTENT_PATH", "ENV" and "NNN". These appear on a few lines in a template
> > f
Thanks. That does help quite a lot.
--
https://mail.python.org/mailman/listinfo/python-list
On Sunday, November 29, 2015 at 3:37:34 PM UTC-6, Mr Zaug wrote:
> The items I'm searching for are few and they do not change. They are
> "CONTENT_PATH", "ENV" and "NNN". These appear on a few lines in a template
> file. They do not appear together on any line and they only appear once on
> eac
On Sun, 29 Nov 2015 13:36:57 -0800, Mr Zaug wrote:
> result = re.sub(pattern, repl, string, count=0, flags=0);
re.sub works on a string, not on a file.
Read the file to a string, pass it in as the string.
Or pre-compile the search pattern(s) and process the file line by line:
import re
pa
I need to use re.sub to replace strings in a text file. I can't seem to
understand how to use the re module to this end.
result = re.sub(pattern, repl, string, count=0, flags=0);
I think I understand that pattern is the regex I'm searching for and repl is
the thing I want to subs
On Tuesday, May 13, 2014 4:26:51 PM UTC-4, MRAB wrote:
>
> 0x96 is a hexadecimal literal for an int. Within a string you need \x96
>
> (it's \x for 2 hex digits, \u for 4 hex digits, \U for 8 hex digits).
Yes, that was my problem. Figured it out just after posting my last message.
using \x96
a hex editor and *hopefully* you will be able
>> >> to
>>
>> >> see chunks of human-readable text where you can identify how
>> >> en-dashes
>>
>> >> and similar are stored.
>>
>>
>> >
>> >I created a .d
> >
>
> >I created a .doc file and opened it with UltraEdit in binary (Hex) mode.
> > What I see is that there are two characters, one for ndash and one for
> > mdash, each a single byte long. 0x96 and 0x97.
>
> >So I tried this: fStr = re.sub(b'\0
dashes
and similar are stored.
I created a .doc file and opened it with UltraEdit in binary (Hex) mode.
What I see is that there are two characters, one for ndash and one for mdash,
each a single byte long. 0x96 and 0x97.
So I tried this: fStr = re.sub(b'\0x96',b'-',fStr)
gt; and similar are stored.
I created a .doc file and opened it with UltraEdit in binary (Hex) mode. What
I see is that there are two characters, one for ndash and one for mdash, each a
single byte long. 0x96 and 0x97.
So I tried this: fStr = re.sub(b'\0x96',b'-',fStr)
On Tue, May 13, 2014 at 11:49 PM, Steven D'Aprano
wrote:
>
> This {EN DASH} is an n-dash.
>
> or:
>
> x\x9c\x0b\xc9\xc8,V\xa8v\xf5Spq\x0c\xf6\xa8U\x00r\x12
> \xf3\x14\xf2tS\x12\x8b3\xf4\x00\x82^\x08\xf8
>
>
> (that last one is the text passed through the zlib compressor)
I had to deco
On Mon, 12 May 2014 10:35:53 -0700, scottcabit wrote:
> On Friday, May 9, 2014 8:12:57 PM UTC-4, Steven D'Aprano wrote:
>
>> Good:
>>
>>
>>
>> fStr = re.sub(b'‒', b'-', fStr)
>>
>>
> Doesn't work...the
On 05/12/2014 01:35 PM, scottca...@gmail.com wrote:
On Friday, May 9, 2014 8:12:57 PM UTC-4, Steven D'Aprano wrote:
Good:
# Untested
fStr = re.sub(b'&#x(201[2-5])|(2E3[AB])|(00[2A]D)', b'-', fStr)
Still doesn't work.
Guess whatever th
On Monday, May 12, 2014 11:05:53 PM UTC+5:30, scott...@gmail.com wrote:
> On Friday, May 9, 2014 8:12:57 PM UTC-4, Steven D'Aprano wrote:
> > fStr = fStr.replace(b'‒', b'-')
>
>Still doesn't work
>
>
> > Best:
> >
> >
On Friday, May 9, 2014 8:12:57 PM UTC-4, Steven D'Aprano wrote:
> Good:
>
>
>
> fStr = re.sub(b'‒', b'-', fStr)
>
Doesn't work...the document has been verified to contain endash and emdash
characters, but this does NOT replace them.
>
On 10/05/2014 08:11, wxjmfa...@gmail.com wrote:
Anyway, as Python may fail as soon as one uses an
EM DASH or an EM DASH, I think it's not worth the
effort to spend to much time with it.
Nope -- seems all right to me. (Hopefully helping the OP out as well as
rebutting a rather foolish assertion
Le samedi 10 mai 2014 06:22:00 UTC+2, Rustom Mody a écrit :
> On Saturday, May 10, 2014 1:21:04 AM UTC+5:30, scott...@gmail.com wrote:
>
> > Hi,
>
> >
>
> >
>
> >
>
> > here is a snippet of code that opens a file (fn contains the path\name)
> > and first tried to replace all endash, emdas
On Saturday, May 10, 2014 1:21:04 AM UTC+5:30, scott...@gmail.com wrote:
> Hi,
>
>
>
> here is a snippet of code that opens a file (fn contains the path\name) and
> first tried to replace all endash, emdash etc characters with simple dash
> characters, before doing a search.
>
> But the re
d with "\x00".
>
> Hmmm..thought that was what I was doing. Can anyone figure out why the
> syntax is wrong for Word 2007 document binary file data?
You are searching for the literal "‒", in other words:
ampersand hash x two zero one two
*not* a FIGURE DASH
string replacement.
> fn = 'z:\Documentation\Software'
> def processdoc(fn,outfile):
> fStr = open(fn, 'rb').read()
> re.sub(b'‒','-',fStr)
Good:
fStr = re.sub(b'‒', b'-', fStr)
Better:
fStr = fStr.replace(b
On Friday, May 9, 2014 4:09:58 PM UTC-4, Tim Chase wrote:
> A Word doc (as your subject mentions) is a binary format. There's
> the older .doc and the newer .docx (which is actually a .zip file
> with a particular content-structure renamed to .docx).
>
I am using .doc files only..
>
> F
>
> re.sub _returns_ its result (strings are immutable).
Ahhso I tried this for each re.sub
fStr = re.sub(b'‒','-',fStr)
No errors running it, but it still does nothing.
--
https://mail.python.org/mailman/listinfo/python-list
Obviously a syntax
> problemwwhat silly thing am I doing wrong?
>
> fn = 'z:\Documentation\Software'
> def processdoc(fn,outfile):
> fStr = open(fn, 'rb').read()
> re.sub(b'‒','-',fStr)
> re.sub(b'–','-
On Sat, May 10, 2014 at 5:51 AM, wrote:
> But the replaces are not having any effect. Obviously a syntax
> problemwwhat silly thing am I doing wrong?
>
> Thanks!
>
> fn = 'z:\Documentation\Software'
> def processdoc(fn,outfile):
> fStr = op
. Obviously a syntax
problemwwhat silly thing am I doing wrong?
Thanks!
fn = 'z:\Documentation\Software'
def processdoc(fn,outfile):
fStr = open(fn, 'rb').read()
re.sub(b'‒','-',fStr)
re.sub(b'–','-',fStr)
re
wrong?
Thanks!
fn = 'z:\Documentation\Software'
def processdoc(fn,outfile):
fStr = open(fn, 'rb').read()
re.sub(b'‒','-',fStr)
re.sub(b'–','-',fStr)
re.sub(b'—','-',fStr)
re.sub(b'―
On Mon, Dec 19, 2011 at 4:15 PM, wrote:
> On Dec 16, 11:49 am, John Gordon wrote:
>> I'm working with IPv6 CIDR strings, and I want to replace the longest
>> match of "(:|$)+" with ":". But when I use re.sub() it replaces
>> the leftmost m
On Dec 16, 11:49 am, John Gordon wrote:
> I'm working with IPv6 CIDR strings, and I want to replace the longest
> match of "(:|$)+" with ":". But when I use re.sub() it replaces
> the leftmost match, even if there is a longer match later in the strin
27;
>> for word in re.findall('((:?)+)', ip6):
>> if len(word[0])> len(longest_match):
>> longest_match = word[0]
>>
>> # if we found a match, replace it with a colon
>> if longest_match:
>>ip6 = re.sub(longest_match, '
On 12/16/2011 1:36 PM, Roy Smith wrote:
What you want is an IPv6 class which represents an address in some
canonical form. It would have constructors which accept any of the
RFC-2373 defined formats. It would also have string formatting methods
to convert the internal form into any of these fo
match, replace it with a colon
if longest_match:
ip6 = re.sub(longest_match, ':', ip6, 1)
For a simple replace, using re is probably overkill. The .replace
method is a better solution:
ip6 = longest_match.replace(ip6, ':', 1)
--
http://mail.python.org/mailman/listinfo/python-list
In Roy Smith writes:
> Having done quite a bit of IPv6 work, my opinion here is that you're
> trying to do The Wrong Thing.
> What you want is an IPv6 class which represents an address in some
> canonical form. It would have constructors which accept any of the
> RFC-2373 defined formats.
In Ian Kelly
writes:
> >>> I'm also looking for a regexp that will remove leading zeroes in each
> >>> four-digit group, but will leave a single zero if the group was all
> >>> zeroes.
> pattern = r'\b0{1,3}([1-9a-f][0-9a-f]*|0)\b'
lon
if longest_match:
ip6 = re.sub(longest_match, ':', ip6, 1)
Thanks!
--
John Gordon A is for Amy, who fell down the stairs
gor...@panix.com B is for Basil, assaulted by bears
-- Edward Gorey, "The Gashlycrumb Ti
In article ,
John Gordon wrote:
> I'm working with IPv6 CIDR strings, and I want to replace the longest
> match of "(:|$)+" with ":". But when I use re.sub() it replaces
> the leftmost match, even if there is a longer match later in the string.
>
On 16/12/2011 17:57, Ian Kelly wrote:
On Fri, Dec 16, 2011 at 10:36 AM, MRAB wrote:
On 16/12/2011 16:49, John Gordon wrote:
According to the documentation on re.sub(), it replaces the leftmost
matching pattern.
However, I want to replace the *longest* matching pattern, which is
not
On Fri, Dec 16, 2011 at 10:57 AM, Ian Kelly wrote:
> On Fri, Dec 16, 2011 at 10:36 AM, MRAB wrote:
>> On 16/12/2011 16:49, John Gordon wrote:
>>>
>>> According to the documentation on re.sub(), it replaces the leftmost
>>> matching pattern.
>>>
On Fri, Dec 16, 2011 at 10:36 AM, MRAB wrote:
> On 16/12/2011 16:49, John Gordon wrote:
>>
>> According to the documentation on re.sub(), it replaces the leftmost
>> matching pattern.
>>
>> However, I want to replace the *longest* matching pattern, which is
>
On 16/12/2011 16:49, John Gordon wrote:
According to the documentation on re.sub(), it replaces the leftmost
matching pattern.
However, I want to replace the *longest* matching pattern, which is
not necessarily the leftmost match. Any suggestions?
I'm working with IPv6 CIDR strings,
it's slice.start and
slice.stop, but match.start() and match.end() ?
On Fri, Dec 16, 2011 at 11:49 AM, John Gordon wrote:
> According to the documentation on re.sub(), it replaces the leftmost
> matching pattern.
>
> However, I want to replace the *longest* matching patter
According to the documentation on re.sub(), it replaces the leftmost
matching pattern.
However, I want to replace the *longest* matching pattern, which is
not necessarily the leftmost match. Any suggestions?
I'm working with IPv6 CIDR strings, and I want to replace the longest
match of &
On 17 Sep, 19:59, Peter Otten <__pete...@web.de> wrote:
> Jon Clements wrote:
> > (I reckon this is probably a question for MRAB and is not really
> > Python specific, but anyhow...)
>
> > Absolutely basic example: re.sub(r'(\d+)', r'\1', '
Jon Clements wrote:
> (I reckon this is probably a question for MRAB and is not really
> Python specific, but anyhow...)
>
> Absolutely basic example: re.sub(r'(\d+)', r'\1', 'string1')
>
> I've been searching around and I'm sure it
On 17/09/2010 19:21, Jon Clements wrote:
Hi All,
(I reckon this is probably a question for MRAB and is not really
Python specific, but anyhow...)
Absolutely basic example: re.sub(r'(\d+)', r'\1', 'string1')
I've been searching around and I'm sure it&
Hi All,
(I reckon this is probably a question for MRAB and is not really
Python specific, but anyhow...)
Absolutely basic example: re.sub(r'(\d+)', r'\1', 'string1')
I've been searching around and I'm sure it'll be obvious when it's
pointed ou
Thomas Jollans wrote:
On Wednesday 18 August 2010, it occurred to Brandon Harris to exclaim:
Having trouble using %s with re.sub
test = '/my/word/whats/wrong'
re.sub('(/)word(/)', r'\1\%s\2'%'1000', test)
return is /my/@0/whats/wrong
This has n
On Wednesday 18 August 2010, it occurred to Brandon Harris to exclaim:
> Having trouble using %s with re.sub
>
> test = '/my/word/whats/wrong'
> re.sub('(/)word(/)', r'\1\%s\2'%'1000', test)
>
> return is /my/@0/whats/wrong
>
T
Having trouble using %s with re.sub
test = '/my/word/whats/wrong'
re.sub('(/)word(/)', r'\1\%s\2'%'1000', test)
return is /my/@0/whats/wrong
however if I cast a value with letters as opposed to numbers
re.sub('(/)word(/)', r'\1\%s\2
gt;> >> You're passing re.IGNORECASE (which happens to equal 2) as a count
>> >> argument, not as a flag. Try this instead:
>>
>> >> >>> re.sub(r"python\d\d" + '(?i)', "Python27", t)
>> >> 'Python27
On Aug 16, 1:46 pm, Alex Willmer wrote:
> "Note that the (?x) flag changes how the expression is parsed. It
> should be used first in the expression string, or after one or more
> whitespace characters. If there are non-whitespace characters before
> the flag, the results are undefined.
> "http://
t;> argument, not as a flag. Try this instead:
>
> >> >>> re.sub(r"python\d\d" + '(?i)', "Python27", t)
> >> 'Python27'
>
> > Basically right, but in-line flags must be placed at the start of a
> > pattern, or the
On Aug 15, 8:07 pm, Steven D'Aprano wrote:
> On Sun, 15 Aug 2010 16:45:49 -0700, Christopher wrote:
> > I have the following problem:
>
> >>>> t="Python26"
> >>>> import re
> >>>> re.sub(r"python\d\d", "
On Sun, 15 Aug 2010 17:36:07 -0700, Alex Willmer wrote:
> On Aug 16, 1:07 am, Steven D'Aprano cybersource.com.au> wrote:
>> You're passing re.IGNORECASE (which happens to equal 2) as a count
>> argument, not as a flag. Try this instead:
>>
>> >>
Alex Willmer wrote:
On Aug 16, 1:07 am, Steven D'Aprano wrote:
You're passing re.IGNORECASE (which happens to equal 2) as a count
argument, not as a flag. Try this instead:
re.sub(r"python\d\d" + '(?i)', "Python27", t)
'Python27'
Basica
On Aug 16, 1:07 am, Steven D'Aprano wrote:
> You're passing re.IGNORECASE (which happens to equal 2) as a count
> argument, not as a flag. Try this instead:
>
> >>> re.sub(r"python\d\d" + '(?i)', "Python27", t)
> 'Python27&
On Sun, 15 Aug 2010 16:45:49 -0700, Christopher wrote:
> I have the following problem:
>
>>>> t="Python26"
>>>> import re
>>>> re.sub(r"python\d\d", "Python27", t)
> 'Python26'
>>>> re.sub(r
I have the following problem:
Python 2.7 (r27:82525, Jul 4 2010, 07:43:08) [MSC v.1500 64 bit
(AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> t="Python26"
>>> import re
>>
ot; % {"var": t}
"Hello wSPAMd".replace("SPAM", t)
or many other variations. Constructing a regex is no different.
You just need to remember that if you pass a string into re.sub as a
replacement then it'll be treated as a template. It's all in the
documentation! :-)
--
http://mail.python.org/mailman/listinfo/python-list
On Thu, 12 Aug 2010 14:33:28 -0700, fuglyducky wrote:
> if anyone happens to know about
> passing a variable into a regex that would be great.
The same way you pass anything into any string.
Regexes are ordinary strings. If you want to construct a string from a
variable t = "orl", you can do an
On Aug 13, 7:33 am, fuglyducky wrote:
> On Aug 12, 2:06 pm, fuglyducky wrote:
>
>
>
> > I have a function that I am attempting to call from another file. I am
> > attempting to replace a string using re.sub with another string. The
> > problem is that the second st
On Aug 12, 2:06 pm, fuglyducky wrote:
> I have a function that I am attempting to call from another file. I am
> attempting to replace a string using re.sub with another string. The
> problem is that the second string is a variable. When I get the
> output, it shows the variable name
I have a function that I am attempting to call from another file. I am
attempting to replace a string using re.sub with another string. The
problem is that the second string is a variable. When I get the
output, it shows the variable name rather than the value. Is there any
way to pass a variable
Thanks for your answers. They helped me to realize that I was
mistakenly using match.string (the whole string) when I should be
using math.group(0) (the whole match).
Best regards,
Javier
--
http://mail.python.org/mailman/listinfo/python-list
On Tue, 06 Jul 2010 19:10:17 +0200, Javier Collado wrote:
> Hello,
>
> Let's imagine that we have a simple function that generates a
> replacement for a regular expression:
>
> def process(match):
> return match.string
>
> If we use that simple function wi
On 07/06/2010 07:10 PM, Javier Collado wrote:
> Hello,
>
> Let's imagine that we have a simple function that generates a
> replacement for a regular expression:
>
> def process(match):
> return match.string
>
> If we use that simple function with re.sub using
Hello,
Let's imagine that we have a simple function that generates a
replacement for a regular expression:
def process(match):
return match.string
If we use that simple function with re.sub using a simple pattern and
a string we get the expected output:
re.sub('123', proce
rocess
> > logic but what a sorprise!!! when arrived to this conclussion after
> > some time debugging i see that:
>
> > import re
> > aa = "zzz:xxx"
> > re.sub(r'(zzz:).*',r'\1'+str(),aa)
> > '[33'
>
>
> some time debugging i see that:
>
> import re
> aa = "zzz:xxx"
> re.sub(r'(zzz:).*',r'\1'+str(),aa)
> '[33'
If you perform the addition you get r"\1". How should the regular
expression engine interpret that? As the back
:
import re
aa = "zzz:xxx"
re.sub(r'(zzz:).*',r'\1'+str(),aa)
'[33'
¿?¿?¿? well lets put a : after the backreference
aa = "zzz:xxx"
re.sub(r'(zzz).*',r'\1:'+str(),aa)
'zzz:'
now its the expected result s
On Oct 16, 9:51 am, MRAB wrote:
> What do you mean "blow up"? It worked for me in Python v2.6.2.
My bad. False alarm. This was one of those cases where a bug in
another area appears like a bug in a different area.
Thank for the help.
cs
--
http://mail.python.org/mailman/listinfo/python-list
Chris Seberino wrote:
What does this line do?...
input_ = re.sub("([a-zA-Z]+)", '"\\1"', input_)
Why don't you try it?
Does it remove parentheses from words?
e.g. (foo) -> foo ???
No, it puts quotes around them.
I'd like to replace [a-zA-Z]
Chris Seberino wrote:
What does this line do?...
input_ = re.sub("([a-zA-Z]+)", '"\\1"', input_)
Does it remove parentheses from words?
e.g. (foo) -> foo ???
I'd like to replace [a-zA-Z] with \w but \w makes it blow up.
In other words, re.sub("(
What does this line do?...
input_ = re.sub("([a-zA-Z]+)", '"\\1"', input_)
Does it remove parentheses from words?
e.g. (foo) -> foo ???
I'd like to replace [a-zA-Z] with \w but \w makes it blow up.
In other words, re.sub("(\w+)", '"\\1
Hi,
Is there a way to flag re.sub not to replace a portion of the string?
I have a very long string that I want to add two new line's to rather
than one, but keep the value X:
string = "testX.\n.today" <-- note X is a value
string = re.sub("testX.\
J Wolfe wrote:
> Hi,
>
> Is there a way to flag re.sub not to replace a portion of the string?
>
> I have a very long string that I want to add two new line's to rather
> than one, but keep the value X:
>
> string = "testX.\n.today" <--
Thanks Duncan,
I did look at that, but it was kinda greek to me. Thanks for pulling
out the part I was looking for that should do the trick.
Jonathan
> http://www.python.org/doc/current/library/re.html#re.sub
>
> > Backreferences, such as \6, are replaced with the substrin
I have a regex that needs multiline flag. Some where I read I
can pass multiline flag in regex string itself without using
re.compile. If anybody have any idea about how to do that
please reply.
As detailed at [1],
"""
(?iLmsux)
(One or more letters from the set 'i', 'L', 'm', 's', 'u', 'x'.)
samba wrote:
I have a regex that needs multiline flag. Some where I read I can pass
multiline flag in regex string itself without using re.compile. If
anybody have any idea about how to do that please reply.
Include "(?m)" in the regular expression for multiline matching. It's
best to put it a
I have a regex that needs multiline flag. Some where I read I can pass
multiline flag in regex string itself without using re.compile. If
anybody have any idea about how to do that please reply.
--
http://mail.python.org/mailman/listinfo/python-list
On Wed, 11 Feb 2009 21:05:53 -, Paul McGuire
wrote:
On Feb 4, 10:51 am, "Emanuele D'Arrigo" wrote:
Hi everybody,
I'm having a ball with the power of regular expression
Don't forget the ball you can have with the power of ordinary Python
strings, string methods, and string interpolati
On Feb 4, 10:51 am, "Emanuele D'Arrigo" wrote:
> Hi everybody,
>
> I'm having a ball with the power of regular expression
Don't forget the ball you can have with the power of ordinary Python
strings, string methods, and string interpolation!
originalString = "spam:%(first)s ham:%(second)s"
print
>
> Book recommendation: _Mastering Regular Expressions_, Jeffrey Friedl
> --
> Aahz (a...@pythoncraft.com) <*> http://www.pythoncraft.com/
I wholeheartedly second this! The third edition is out now.
--
http://mail.python.org/mailman/listinfo/python-list
In article <4c7158d2-5663-46b9-b950-be81bd799...@z6g2000pre.googlegroups.com>,
Emanuele D'Arrigo wrote:
>
>I'm having a ball with the power of regular expression but I stumbled
>on something I don't quite understand:
Book recommendation: _Mastering Regular Expressions_, Jeffrey Friedl
--
Aahz (a
> Hi everybody,
>
> I'm having a ball with the power of regular expression but I stumbled
> on something I don't quite understand:
>
> theOriginalString = "spam:(?P.*) ham:(?P.*)"
> aReplacementPattern = "\(\?P.*\)"
> aReplacementString= &
On Feb 4, 5:17 pm, MRAB wrote:
> You could use the lazy form "*?" which tries to match as little as
> possible, eg "\(\?P.*?\)" where the ".*?" matches:
> spam:(?P.*) ham:(?P.*)
> giving "spam:foo ham:(?P.*)".
A-ha! Of course! That makes perfect sense! Thank you! Problem solved!
Ciao!
Manu
--
Emanuele D'Arrigo wrote:
> Hi everybody,
>
> I'm having a ball with the power of regular expression but I stumbled
> on something I don't quite understand:
>
> theOriginalString = "spam:(?P.*) ham:(?P.*)"
> aReplacementPattern = "\(\?P.*\)"
Hi everybody,
I'm having a ball with the power of regular expression but I stumbled
on something I don't quite understand:
theOriginalString = "spam:(?P.*) ham:(?P.*)"
aReplacementPattern = "\(\?P.*\)"
aReplacementString= "foo"
re.sub(aReplacementPattern
En Thu, 31 Jan 2008 01:01:30 -0200, Astan Chee <[EMAIL PROTECTED]> escribió:
> I have a html text stored as a string. Now I want to go through this
> string and find all 6 digit numbers and make links from them.
> Im using re.sub and for some reason its not picking up the previ
1 - 100 of 159 matches
Mail list logo