| | |
regex (boost)
Please support our C++ advertiser: Intel Parallel Studio Home
![]() |
•
•
Join Date: Oct 2006
Posts: 9
Reputation:
Solved Threads: 0
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
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
- match_regex iterator syntax (C++)
- Equivalent match_results prog of this: (C++)
- Regex for password (Shell Scripting)
- Regex in C++ (C++)
- Desiging a set of rules for a match (C++)
- help with regex...and marking up text in JTextpane with html (Java)
- How to get an extra boost from your graphics card. (Windows tips 'n' tweaks)
Other Threads in the C++ Forum
- Previous Thread: Coke Machine
- Next Thread: help!
| Thread Tools | Search this Thread |
api array based binary bitmap c++ c/c++ calculator char char* class classes code coding compile console conversion database delete deploy desktop developer directshow dll download dynamic dynamiccharacterarray email encryption error file forms fstream function functions game givemetehcodez google graph gui homeworkhelp iamthwee ifstream input int integer java lib linkedlist linker linux list loop looping loops map math matrix memory multiple news node number numbertoword output pointer problem program programming project python random read recursion recursive reference return rpg sorting string strings temperature template templates test text text-file tree unix url variable vector video visualstudio win32 windows winsock word wordfrequency wxwidgets






