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
M
c M
wM
a
c a
wa
r
c r
wr
usstatear
varMar
wordMar
monthMar
_
c _
ws_
2
c 2
d2
9
c 9
d9
_
c _
ws_
1
c 1
d1
9
c 9
d9
:
c :
2
c 2
d2
1
c 1
d1
:
c :
4
c 4
d4
5
c 5
d5
mmddyy
time19:21:45
_
c _
ws_
g
c g
wg
a
c a
wa
n
c n
wn
d
c d
wd
a
c a
wa
l
c l
wl
f
c f
wf
vargandalf
wordgandalf
_
c _
ws_
g
c g
wg
e
c e
we
n
c n
wn
u
c u
wu
n
c n
wn
i
c i
wi
x
c x
wx
vargenunix
word
:
c :
_
c _
ws_
[
c [
I
c I
wI
D
c D
wD
varID
wordID
usstateID
_
c _
ws_
9
c 9
d9
3
c 3
d3
6
c 6
d6
7
c 7
d7
6
c 6
d6
9
c 9
d9
_
c _
ws_
k
c k
wk
e
c e
we
r
c r
wr
n
c n
wn
varkern
wordkern
.
c .
i
c i
wi
n
c n
wn
f
c f
wf
o
c o
wo
varinfo
wordinfo
fqdnkern.info
]
c ]
sbraces[ID_936769_kern.info]
_
c _
ws_
d
c d
wd
t
c t
wt
r
c r
wr
a
c a
wa
c
c c
wc
e
c e
we
worddtrace
0
c 0
d0
vardtrace0
alphanumdtrace0
_
c _
ws_
i
c i
wi
s
c s
ws
varis
wordis
_
c _
ws_
/
c /
p
c p
wp
s
c s
ws
e
c e
we
u
c u
wu
d
c d
wd
o
c o
wo
varpseudo
wordpseudo
/
c /
d
c d
wd
t
c t
wt
r
c r
wr
a
c a
wa
c
c c
wc
e
c e
we
vardtrace
worddtrace
unixpath/pseudo/dtrace
@
c @
0
c 0
d0
< Source String
What to click?  extract any integer in this position
extract this integer (2006) in this position
 
3C 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-cpcre.php3?s=Mar%2029%2019:21:45%20gandalf%20genunix:%20%5BID%20936769%20kern.info%5D%20dtrace0%20is%20/pseudo/[email protected]&5&7

#include <stdio.h>
#include <string.h>
#include <pcre.h>

int main(int argc, char **argv)
{
  const char *error;
  int erroffset;
  int ovector[186];
  char re[8192]="";
  char txt[]="Mar 29 19:21:45 gandalf genunix: [ID 936769 kern.info] dtrace0 is /pseudo/[email protected]";

  char re1[]=".*?";	// Non-greedy match on filler
  strcat(re,re1);
  char re2[]="((?:[0]?[1-9]|[1][012])[-:\\/.](?:(?:[0-2]?\\d{1})|(?:[3][01]{1}))[-:\\/.](?:(?:\\d{1}\\d{1})))(?![\\d])";	// MMDDYY 1
  strcat(re,re2);
  char re3[]=".*?";	// Non-greedy match on filler
  strcat(re,re3);
  char re4[]="(?:[a-z][a-z]+)";	// Uninteresting: word
  strcat(re,re4);
  char re5[]=".*?";	// Non-greedy match on filler
  strcat(re,re5);
  char re6[]="((?:[a-z][a-z]+))";	// Word 1
  strcat(re,re6);

  pcre *r =  pcre_compile(re, PCRE_CASELESS|PCRE_DOTALL, &error, &erroffset, NULL);
  int rc = pcre_exec(r, NULL, txt, strlen(txt), 0, 0, ovector, 186);
  if (rc>0)
  {
      char mmddyy1[1024];
      pcre_copy_substring(txt, ovector, rc,1,mmddyy1, 1024);
      printf("(%s)",mmddyy1);
      char word1[1024];
      pcre_copy_substring(txt, ovector, rc,2,word1, 1024);
      printf("(%s)",word1);
      puts("\n");
  }
}

//-----
// C does not provide a regular expression feature as standard.
//
// To run this code you will need to first download and install
// the PCRE library from http://www.pcre.org/
//
// Note that on Linux systems PCRE is often already installed in /usr/lib/libpcre* or /usr/local/lib/libpcre*. 
//
// Compile and on Unix using:
// # gcc -lpcre x.c
// # ./a.out
//
 
 
  home     faq              ©2006 mark james ennis