Can someone help me with understanding how python uses backreferences?
I need to remember the item that was last matched by the re engine but i
cant seem to understand anything that I find on backreferences. if I
want to access the last match do i use \number or is there something
else i have to do?
heres part of my code:
renDate = re.compile("$(( \d){4}-(\d){2}-(\d){2}))")
renDate.search( l)
if(exist.search (l) and str(lastmodDate ) < \1): #i need help here with \1
Thanks in advance
A.D 4 1896
Amy Dillavou wrote: Can someone help me with understanding how python uses backreferences? I need to remember the item that was last matched by the re engine but i cant seem to understand anything that I find on backreferences. if I want to access the last match do i use \number or is there something else i have to do?
heres part of my code: renDate = re.compile("$(( \d){4}-(\d){2}-(\d){2}))") renDate.search( l) if(exist.search (l) and str(lastmodDate ) < \1): #i need help here with \1
Thanks in advance A.D
I haven't had to use backreferences yet, so I don't know offhand how to
go about it. What I do know is that this online book is very useful: http://gnosis.cx/TPiP/
Chapter 3 covers REs: http://gnosis.cx/TPiP/chap3.txt
From what I remember, in python you can use numbered backreferences (up
to 99), or named ones.
Iain
"Amy Dillavou" <gs****@line72. net> wrote in message
news:ma******** *************** **************@ python.org... Can someone help me with understanding how python uses backreferences? I need to remember the item that was last matched by the re engine but i cant seem to understand anything that I find on backreferences. if I want to access the last match do i use \number or is there something else i have to do?
heres part of my code: renDate = re.compile("$(( \d){4}-(\d){2}-(\d){2}))") renDate.search( l) if(exist.search (l) and str(lastmodDate ) < \1): #i need help here with \1
Thanks in advance A.D
renDate = re.compile(some _regex)
match = renDate.search( input)
if match and str(lastmodDate ) < match.group(1):
do_something()
HTH,
George
George and Iain -
Thanks for your help!!! It worked for me, and that book seems to be
really useful =)
A.D
On Wed, 2005-09-28 at 11:16 -0400, George Sakkis wrote: "Amy Dillavou" <gs****@line72. net> wrote in message news:ma******** *************** **************@ python.org... Can someone help me with understanding how python uses backreferences? I need to remember the item that was last matched by the re engine but i cant seem to understand anything that I find on backreferences. if I want to access the last match do i use \number or is there something else i have to do?
heres part of my code: renDate = re.compile("$(( \d){4}-(\d){2}-(\d){2}))") renDate.search( l) if(exist.search (l) and str(lastmodDate ) < \1): #i need help here with \1
Thanks in advance A.D
renDate = re.compile(some _regex) match = renDate.search( input) if match and str(lastmodDate ) < match.group(1): do_something()
HTH, George
Iain King wrote: Amy Dillavou wrote:
Can someone help me with understanding how python uses backreferences? I need to remember the item that was last matched by the re engine but i cant seem to understand anything that I find on backreferences. if I want to access the last match do i use \number or is there something else i have to do?
heres part of my code: renDate = re.compile("$(( \d){4}-(\d){2}-(\d){2}))") renDate.searc h(l) if(exist.sear ch(l) and str(lastmodDate ) < \1): #i need help here with \1
Thanks in advance A.D
I haven't had to use backreferences yet, so I don't know offhand how to go about it. What I do know is that this online book is very useful:
http://gnosis.cx/TPiP/
Chapter 3 covers REs:
http://gnosis.cx/TPiP/chap3.txt
From what I remember, in python you can use numbered backreferences (up to 99), or named ones.
Iain
This shows both named backreferences and indexed. In both the
replacement and the searching.
(?P<name>data) sets the value of a named backreference named name to the
value of data (but can only be used in the pattern).
\NUMBER gets the value of a backreference by its index (can be used in
the pattern or the replacement).
(?P=name) gets the value of a named backreference (but only in the pattern).
\g<name> gets the value of a named backreference (but only in the
replacement).
Example:
re.sub(r"""<(?P <tag>H[1-5]) style="(.*)">(? P<text>.*)</(?P=tag)>""",
r"""<B style="\2">\g<t ext></B> | <\1 style="\2">\3<\ 1>""",
"""<H1 style="color: #000000">abc</H1>"""
)
HTH,
Peter This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Thomas Mlynarczyk |
last post by:
Quote from PHP Manual:
A back reference matches whatever actually matched the capturing
subpattern in the current subject string, rather than
anything matching the subpattern itself. So the pattern
(sens|respons)e and \1ibility
matches "sense and sensibility" and "response and responsibility",
but not "sense and responsibility".
|
by: higabe |
last post by:
Three questions
1)
I have a string function that works perfectly but according to W3C.org
web site is syntactically flawed because it contains the characters </
in sequence. So how am I supposed to write this function?
String.replace(/</g,'<');
|
by: CSN |
last post by:
Can you use backreferences in regular expressions like
so?
update table set title='foobar ' || \1 where title ~*
'+(+)';
|
by: Martin Lucas-Smith |
last post by:
Is there any way to use backreferences _within_ a _pattern_, as works on
some regexp parsing applications, i.e.
'<a href="mailto:(*)@(*)">\\1@\\2</a>'
=>
'\\1@\\2'
so that
<a href="mailto:foo@example.com">foo@example.com</a>
WOULD match and be replaced by foo@example.com
|
by: Pankaj |
last post by:
I have something like below in perl and i am searching for equivalent
in python:
::: Perl :::
***********
while( <FILEHANDLE> )
{
line = $_;
| |
by: Allen |
last post by:
For my web-based php regex find/replace do-hickey, I need to match
individual back references and wrap a tag around them so they'll be unique
to the rest of the match for individual color markup. Initially this
would seem easy enough, however not all of a potential regex match is
going to be within a back reference. So it's necessary to replace the
back reference, and only the back reference, while preserving the context
of the match. ...
|
by: everymn |
last post by:
Could someone tell me what I'm doing wrong to cause the backreference
variable to fail to be assigned here? It's entering the If block 4
times, so I know it's matching but there's nothing in $1?
Thank You!
#! /usr/bin/perl
use warnings;
use strict;
|
by: TenTen |
last post by:
hi, I'm a regex beginer and I want to know if with backreferences \1 I can reduce the ip test regex that I found on a web site :
\b (25 |2 | ? ?)\. (25 |2 | ? ?)\. (25 |2 | ? ?)\. (25 |2 | ? ?)\b
By something like that : \b (25 |2 | ? ?)\.)\1\1 (25 |2 | ? ?)\b?
I ask that in aim of understand backreferences thank you for answer me.
(@^_^@)
|
by: Uwe Schmitt |
last post by:
Hi,
Is anobody aware of this post: http://swtch.com/~rsc/regexp/regexp1.html
?
Are there any plans to speed up Pythons regular expression module ?
Or
is the example in this artricle too far from reality ???
Greetings, Uwe
|
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
| |
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
| |
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |