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
4
c 4
d
2
c 2
d2
2
int42
_
c _
ws_
4
c 4
d4
3
c 3
d3
day3
int
< 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://txt2re.com/index-cpcre.php3?s=42%2043&2&8&-3

#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[]="42 43";

  char re1[]="(\\d)";	// Any Single Digit 1
  strcat(re,re1);
  char re2[]="(2)";	// Day 1
  strcat(re,re2);
  char re3[]=".*?";	// Non-greedy match on filler
  strcat(re,re3);
  char re4[]="(\\d+)";	// Integer Number 1
  strcat(re,re4);

  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 d1[1024];
      pcre_copy_substring(txt, ovector, rc,1,d1, 1024);
      printf("(%s)",d1);
      char day1[1024];
      pcre_copy_substring(txt, ovector, rc,2,day1, 1024);
      printf("(%s)",day1);
      char int1[1024];
      pcre_copy_substring(txt, ovector, rc,3,int1, 1024);
      printf("(%s)",int1);
      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
//
 
 
 
 
Feedback
:: Excellent toolThu, 30 Oct 2014 08:31AM
:: Very nice...!Thu, 30 Oct 2014 09:29AM
Ozair:: Nice working (Y)Thu, 30 Oct 2014 05:16PM
:: I would like to see a feature to give a generic regex expression instead of a whole script. I also second the request to submit a list of strings and return a single regex to match them all.Mon, 3 Nov 2014 08:24PM
:: Amazing!Tue, 4 Nov 2014 01:15AM
:: cool!Tue, 4 Nov 2014 01:06PM
:: This will come in handy.Fri, 7 Nov 2014 02:25PM
anon:: I second the feature request for a generic regex rather than a whole script. As great as it is having the whole script there, just the regex would be ideal sometimes.Fri, 7 Nov 2014 04:03PM
Jason:: Love to see what people have already suggested/requested: unix/linux utilities sed and grepFri, 7 Nov 2014 09:23PM
Андрей Викторович::  Mon, 10 Nov 2014 08:13PM
Larry:: Thank youMon, 10 Nov 2014 09:05PM
kdnhkb:: VPVAuhBEkzPzcWQhcTwTue, 11 Nov 2014 06:48AM
:: 13152027278Tue, 11 Nov 2014 09:40AM
Sporri:: Awesome tool! Thank you.Tue, 11 Nov 2014 11:50AM
K Neeraj Lal:: Awesome tool!!!Wed, 12 Nov 2014 08:21AM
::  Wed, 12 Nov 2014 09:12AM
:: gud oneWed, 12 Nov 2014 11:41AM
::  Wed, 12 Nov 2014 11:11PM
python::  Thu, 13 Nov 2014 09:02AM
::  Thu, 13 Nov 2014 11:08AM
Anon:: Great tool! Thank YouThu, 13 Nov 2014 09:55PM
Anon:: what about repeating structures? like 4%,6%,8%,9%,...,n% for which the regex is ^\d+%(?:,\d+%)+$Fri, 14 Nov 2014 01:42PM
:: ngentotFri, 14 Nov 2014 05:21PM
:: ah ah ah ah Fri, 14 Nov 2014 05:21PM
Андрей Викторович::  Fri, 14 Nov 2014 07:56PM
timtjtim:: Wow! Saved so much time!Fri, 14 Nov 2014 09:25PM
::  Sun, 16 Nov 2014 04:21PM
anon:: Dang!!!Sun, 16 Nov 2014 04:21PM
agxyokc:: BpcLNpZfPzCmWWSun, 16 Nov 2014 09:42PM
Alicia:: Amazing tool, just what i was looking for!Sun, 16 Nov 2014 11:22PM
:: LOVE U DUDE! Mon, 17 Nov 2014 09:42AM
:: First LastTue, 18 Nov 2014 03:29PM
taht:: si loocThu, 20 Nov 2014 10:54AM
evol:: amilThu, 20 Nov 2014 10:54AM
This rocks my socks'"!:: Very good and a big'o! variety"sh`Thu, 20 Nov 2014 02:21PM
This rocks my socks'"!:: Very good and a big'o! variety"sh`Thu, 20 Nov 2014 02:21PM
This rocks my socks'"!:: Very good and a big'o! variety"sh`Thu, 20 Nov 2014 02:21PM
This rocks my socks'"!:: Very good and a big'o! variety"sh`Thu, 20 Nov 2014 02:21PM
This rocks my socks'"!:: Very good and a big'o! variety"sh`Thu, 20 Nov 2014 02:21PM
This rocks my socks'"!:: Very good and a big'o! variety"sh`Thu, 20 Nov 2014 02:21PM
This rocks my socks'"!:: Very good and a big'o! variety"sh`Thu, 20 Nov 2014 02:21PM
Thanks A Million:: This works great. I used extract function to replace the txt variable. Works like a charm. Thanks LawrenceThu, 20 Nov 2014 10:01PM
venk13:: In-f*cking-sane!Fri, 21 Nov 2014 10:18AM
Андрей Викторович::  Fri, 21 Nov 2014 10:18AM
 
  home     faq              ©2006 mark james ennis