regex (boost)

Please support our C++ advertiser: Intel Parallel Studio Home
Reply

Join Date: Oct 2006
Posts: 9
Reputation: l2u is an unknown quantity at this point 
Solved Threads: 0
l2u l2u is offline Offline
Newbie Poster

regex (boost)

 
0
  #1
Oct 10th, 2006
Hello..

Im working on my c++ application, and I have string (user input) where I would have to replace some variables/substrings in it..
For example lets say user give input:
string str "this is test $some_variable some more text $random(1-5) $random(1-9)";

My program has a vector <string> of variables that program should look for, for this case lets say "some_variable" and "random".
Now I want to replace $some_variable and both $random 'variables' with another string, and I want $some_variable to be replaced with some other string, and $random to be replaced with random number generated in range from 1-5 and 1-9, for instance $random(1-5) = "3", $random(1-9) = "6".

So I would get "this is test some string some more text 3 6";

This would be an easy thing to do, if I wouldnt have $random variable which makes different string each time you call it, so I'm in concern what would be a right/best approach to this.. I was thinking of using boost::regex and search with boost::regex expression("[%$](some_variable|random|some_more_variables)(<([^>]+)>)?"); until I come to the string end..

Thanks a lot for help
Kind regards
Last edited by l2u; Oct 10th, 2006 at 5:27 pm.
Reply With Quote Quick reply to this message  
Join Date: Aug 2005
Posts: 5,264
Reputation: iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold 
Solved Threads: 377
Featured Poster
iamthwee's Avatar
iamthwee iamthwee is offline Offline
Posting Expert

Re: regex (boost)

 
0
  #2
Oct 11th, 2006
yeah using some sort of regex library would seem like a sensible option.
*Voted best profile in the world*
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC