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
T
c T
wT
h
c h
wh
i
c i
wi
s
c s
ws
varThis
wordThis
_
c _
ws_
s
c s
ws
t
c t
wt
r
c r
wr
i
c i
wi
n
c n
wn
g
c g
wg
varstring
wordstring
_
c _
ws_
c
c c
wc
o
c o
wo
n
c n
wn
t
c t
wt
a
c a
wa
i
c i
wi
n
c n
wn
s
c s
ws
varcontains
wordcontains
_
c _
ws_
t
c t
wt
e
c e
we
s
c s
ws
t
c t
wt
vartest
test
_
c _
ws_
i
c i
wi
n
c n
wn
varin
wordin
usstatein
_
c _
ws_
i
c i
wi
t
c t
wt
varit
wordit
_
c _
ws_
a
c a
wa
n
c n
wn
d
c d
wd
usstatend
varand
wordand
_
c _
ws_
e
c e
we
n
c n
wn
d
c d
wd
s
c s
ws
varends
wordends
_
c _
ws_
i
c i
wi
n
c n
wn
varin
wordin
usstatein
_
c _
ws_
y
c y
wy
e
c e
we
s
c s
ws
varyes
yes
< Source String
What to click?  extract any integer in this position
extract this integer (2006) in this position
 
3Perl 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/perl

# URL that generated this code:
# http://txt2re.com/index.php3?s=This%20string%20contains%20test%20in%20it%20and%20ends%20in%20yes&-12&-7

$txt='This string contains test in it and ends in yes';

$re1='.*?';	# Non-greedy match on filler
$re2='(test)';	# Word 1
$re3='.*?';	# Non-greedy match on filler
$re4='(yes)';	# Word 2

$re=$re1.$re2.$re3.$re4;
if ($txt =~ m/$re/is)
{
    $word1=$1;
    $word2=$2;
    print "($word1) ($word2) \n";
}

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