LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 11-24-2010, 03:38 PM   #1
ppmoore
LQ Newbie
 
Registered: Sep 2006
Posts: 25

Rep: Reputation: 0
Using regexec() to parse for multiple substrings


Hello,

I'm trying to use regcomp() and regexec() to parse long string into constituent substrings.

The string itself consists of comma-separated alphanumeric characters, as follows:
H,2,1,1,I,5,0,1,I,5,1,2,P,7,0,1,1,P,7,0,1,2

I would like to break the string into three substrings:
H,2,1,1,
I,5,0,1,I,5,1,2,
P,7,0,1,1,P,7,0,1,2

My code is:

Code:
char* test = "H,2,1,1,I,5,0,1,I,5,1,2,P,7,0,1,1,P,7,0,1,2";
char* pattern = "H(,[0-9]){3},I(,[0-9]){3},P(,[0-9]){4}";
regex_t rexpr;
regmatch_t match[3];

if( ( result = regcomp( &rexpr, pattern, 0 ) ) )
{
  printf("Cannot compile pattern");
  exit();
}

if( regexec(&rexpr, test, 3, &match[0], 0 ) ) 
{
  printf("Cannot parse string");
  exit();
}
I've found several code examples showing how to parse one substring. Is it possible to parse three substrings?

Many thanks,
Paul
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Parse multiple variable from text file with bash Goni Programming 2 07-13-2010 02:25 AM
Multiple MySQL queries or to parse with PHP? jaakkop Programming 4 04-13-2010 11:17 AM
use of regcomp and regexec sancho1980 Programming 5 03-02-2009 10:55 AM
[SOLVED] Problems using regex 'es: regcomp/regexec dedec0 Programming 5 06-15-2007 10:49 AM
Substrings in C marri Programming 4 08-24-2004 04:52 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 06:47 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration