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
"
c "
R
c R
wR
o
c o
wo
b
c b
wb
e
c e
we
r
c r
wr
t
c t
wt
varRobert
wordRobert
_
c _
ws_
D
c D
wD
o
c o
wo
n
c n
wn
h
c h
wh
a
c a
wa
n
c n
wn
varDonhan
wordDonhan
"
c "
string"Robert_Donhan"
_
c _
ws_
<
c <
b
c b
wb
o
c o
wo
b
c b
wb
varbob
wordbob
@
c @
e
c e
we
m
c m
wm
a
c a
wa
i
c i
wi
l
c l
wl
usstateil
varemail
wordemail
.
c .
c
c c
wc
o
c o
wo
m
c m
wm
varcom
wordcom
fileemail.com
fqdnemail.com
email
>
c >
tag<bob@email.com>
< Source String
What to click?  extract any integer in this position
extract this integer (2006) in this position
 
3Java 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 
 
// URL that generated this code:
// http://www.txt2re.com/index-java.php3?s=%22Robert%20Donhan%22%20%3Cbob@email.com%3E&3 

import java.util.regex.*;

class Main
{
  public static void main(String[] args)
  {
    String txt="\"Robert Donhan\" <bob@email.com>";

    String re1=".*?";	// Non-greedy match on filler
    String re2="([\\w-+]+(?:\\.[\\w-+]+)*@(?:[\\w-]+\\.)+[a-zA-Z]{2,7})";	// Email Address 1

    Pattern p = Pattern.compile(re1+re2,Pattern.CASE_INSENSITIVE | Pattern.DOTALL);
    Matcher m = p.matcher(txt);
    if (m.find())
    {
        String email1=m.group(1);
        System.out.print("("+email1.toString()+")"+"\n");
    }
  }
}

//-----
// This code is for use with Sun's Java VM - see http://java.sun.com/ for downloads. 
//
// Paste the code into a new java application or a file called 'Main.java'
//
// Compile and run in Unix using:
// # javac Main.java 
// # java Main 
//
 
 
  home     faq              ©2006 mark james ennis