473,395 Members | 1,680 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

Regular Expresions in C

What i need to do to use Regex in C?

Any help?
Oct 25 '06 #1
3 1407
RADAR
21
Expand|Select|Wrap|Line Numbers
  1. #include // sys/types.h
  2.  
  3. #include // regex.h
  4.  
  5.  
  6.  
  7.  
  8. int match(const char *string, char *pattern) {
  9.  
  10.   int status;
  11.  
  12.   regex_t re;
  13.  
  14.  
  15.  
  16.   if(regcomp(&re, pattern, REG_EXTENDED|REG_NOSUB) != 0) {
  17.  
  18.     return 0; }
  19.  
  20.   status = regexec(&re, string, (size_t)0, NULL, 0);
  21.  
  22.   regfree(&re);
  23.  
  24.   if(status != 0) {
  25.  
  26.     return 0; }
  27.  
  28.   return 1; } 
  29.  
Also there is a shortcut without the header file
int error;
Expand|Select|Wrap|Line Numbers
  1.   regex_t pdata;
  2.   regmatch_t pmatch[3];
  3.  
  4.   if (error = regcomp(&pdata, "a\([bc]*\)a\([bc]*\)a", 0) {
  5.     /* handle error */
  6.   } else if (error = regexec(&pdata, "xxxabcbabbcaxxx", 3, pmatch, 0) {
  7.     /* handle error */
  8.   } else {
  9.     printf("The regex matches from %d to %d.\n",
  10.             pmatch[0].rm_so, pmatch[0].rm_eo);
  11.     regfree(&pdata);
  12.   }
respects,
Oct 25 '06 #2
Banfa
9,065 Expert Mod 8TB
I think you will find that these functions are not standard C (or C++) however if your system supports them then use them but remember using them will reduce the portability of your code.
Oct 25 '06 #3
Thanks for replying =)
Oct 25 '06 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

6
by: Tony C | last post by:
I'm writing a python program which uses regular expressions, but I'm totally new to regexps. I've got Kuchling's "Regexp HOWTO", "Mastering Regular Expresions" by Oreilly, and have access to...
1
by: Kenneth McDonald | last post by:
I'm working on the 0.8 release of my 'rex' module, and would appreciate feedback, suggestions, and criticism as I work towards finalizing the API and feature sets. rex is a module intended to make...
3
by: Jamie Pittman via AccessMonster.com | last post by:
I am having trouble bellow wit this query. I have the total regular hours and the overtime. The problem is that if it is 8 hours and under, I need it to show as regular hours. Any thoughts? ...
4
by: Buddy | last post by:
Can someone please show me how to create a regular expression to do the following My text is set to MyColumn{1, 100} Test I want a regular expression that sets the text to the following...
1
by: Kenny M. | last post by:
Where can I learn to write Regular Expresions e.g. I need to validate the time format HH:mm a.m. it look simple. I want to use a regularExpression validator but It seem complicated to write...
7
by: Billa | last post by:
Hi, I am replaceing a big string using different regular expressions (see some example at the end of the message). The problem is whenever I apply a "replace" it makes a new copy of string and I...
5
by: Josema | last post by:
Hi to all, i did this regular expresion <!--!.*!--> that matchs all occurrences of type <!--!Name!--> <!--!Description!--> and so on... I would like to know the regular expression to get...
1
by: Kamikazy | last post by:
Hi! Can someone tell me from where could I download regular expresions for programming language C? I'm working on a simple compiler and using Lex for creating Lexical Analyser so i need R.E....
25
by: Mike | last post by:
I have a regular expression (^(.+)(?=\s*).*\1 ) that results in matches. I would like to get what the actual regular expression is. In other words, when I apply ^(.+)(?=\s*).*\1 to " HEART...
4
by: jpluttme | last post by:
I need to replace not just the ASC or DESC but the value it's sorting by. i.e. in a string like this: http://www.mysite.com/page1.php?value=uservalue1&sort=ORDER+BY+uservalue1+DESC I've not had...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.