944,199 Members | Top Members by Rank

Ad:
  • C++ Discussion Thread
  • Unsolved
  • Views: 2265
  • C++ RSS
Oct 10th, 2006
0

regex (boost)

Expand Post »
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.
Similar Threads
l2u
Reputation Points: 10
Solved Threads: 0
Newbie Poster
l2u is offline Offline
9 posts
since Oct 2006
Oct 11th, 2006
0

Re: regex (boost)

yeah using some sort of regex library would seem like a sensible option.
Featured Poster
Reputation Points: 1536
Solved Threads: 431
Posting Expert
iamthwee is offline Offline
5,865 posts
since Aug 2005

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in C++ Forum Timeline: Coke Machine
Next Thread in C++ Forum Timeline: help!





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC