469,356 Members | 1,994 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,356 developers. It's quick & easy.

variables is regexp

Hi.
It would be nice to have the possibility to define variables inside
regexp.

Ad example:
(?$identifier=regexp) for defining variables
(?$identifier) for accessing variables.
Thanks and regards Manlio Perillo
Jul 18 '05 #1
1 1394

[Manlio]
It would be nice to have the possibility to define variables inside
regexp.

Ad example:
(?$identifier=regexp) for defining variables
(?$identifier) for accessing variables.


You can, using (?P<name>regex) to define them and (?P=name) to access them.
Here's my favourite example of regular expression abuse, using them to find
prime numbers:
import re
for i in range(2, 1000):
if not re.match(r'(?P<factor>xx+)(?P=factor)+$', 'x'*i):
print i

2
3
5
7
11
....

--
Richie Hindle
ri****@entrian.com
Jul 18 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

10 posts views Thread by Anand Pillai | last post: by
5 posts views Thread by Lukas Holcik | last post: by
1 post views Thread by David Frauzel | last post: by
1 post views Thread by es_ | last post: by
4 posts views Thread by Matt | last post: by
11 posts views Thread by sinbad | last post: by
reply views Thread by zhoujie | last post: by
reply views Thread by suresh191 | last post: by
1 post views Thread by Marylou17 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.