txt 2 re
knowing is obsolete :: regular expression generator (perl php python java javascript coldfusion c c++ ruby vb vbscript j# c# c++.net vb.net)
 
 
 
Enter the string that you want to use a regular expression on:
1
   
 
Select the elements that you want to extract to run regular expression generator:
2
a
c a
wa
r
c r
wr
n
c n
n
a
c a
wa
b
c b
wb
vararnab
wordarnab
'
c '
s
c s
ws
vars
_
c _
ws_
w
c w
ww
o
c o
wo
r
c r
wr
l
c l
wl
d
c d
wd
var
wordworld
_
c _
ws_
i
c i
wi
s
c s
ws
varis
wordis
_
c _
ws_
a
c a
wa
w
c w
ww
e
c e
we
s
c s
ws
o
c o
wo
m
c m
wm
e
c e
we
usstateme
var
wordawesome
< Source String
What to click?  extract any integer in this position
extract this integer (2006) in this position
 
3Python regular expression program that extracts the selected elements from the entered string:
Perl PHP [Python] Java Javascript ColdFusion C C++ Ruby VB VBScript J#.net C#.net C++.net VB.net 
 
#!/usr/bin/python
# URL that generated this code:
# http://www.txt2re.com/index-python.php3?s=arnab%27s%20world%20is%20awesome&2&-32&-24&6

import re

txt='arnab\'s world is awesome'

re1='.*?'	# Non-greedy match on filler
re2='(n)'	# Any Single Word Character (Not Whitespace) 1
re3='.*?'	# Non-greedy match on filler
re4='(?:[a-z][a-z0-9_]*)'	# Uninteresting: var
re5='.*?'	# Non-greedy match on filler
re6='(?:[a-z][a-z0-9_]*)'	# Uninteresting: var
re7='.*?'	# Non-greedy match on filler
re8='((?:[a-z][a-z0-9_]*))'	# Variable Name 1
re9='.*?'	# Non-greedy match on filler
re10='(?:[a-z][a-z0-9_]*)'	# Uninteresting: var
re11='.*?'	# Non-greedy match on filler
re12='((?:[a-z][a-z0-9_]*))'	# Variable Name 2

rg = re.compile(re1+re2+re3+re4+re5+re6+re7+re8+re9+re10+re11+re12,re.IGNORECASE|re.DOTALL)
m = rg.search(txt)
if m:
    w1=m.group(1)
    var1=m.group(2)
    var2=m.group(3)
    print "("+w1+")"+"("+var1+")"+"("+var2+")"+"\n"

#-----
# Paste the code into a new python file. Then in Unix:'
# $ python x.py 
#-----
 
 
  home     faq              ©2006 mark james ennis