Hi,
I am in need for Regular Expression pattern that could help me parse what I would call tokens. Currently, I am parsing a string character by character and using a scanner approach (Sort of how compiler works). However, I would think a RegExp would perform better.
Here is the scenario: Everything that is used within a “()” is called a token. A token could have nested tokens. An example would be:
Say, I have a token called (CurrentUser)and I have another token called (Date). Each token could support embedded attributes inside it. For example, the Date might have format=”Long|short|longtime|shortime”.
So if I have a string that is “(CurrentUser) logged on (Date: format=”short”). I should be able to replace that string by “John Smith logged on 03/30/3008” That was simple, however it could get more complex. For example say “(CurrentUser) logged on (Date: format=”(defaultFormat)” ) . the way my algorithm works is first I find inner tokens
(CurrentUser) : John Smith
(defaultFormat) : Long
Step 1 “(CurrentUser) logged on (Date: format=”(defaultFormat)” )
Step2 “(CurrentUser) logged on (Date: format=”long” )
At this point, I start processing form start again and I will do string replacement on the tokens.
I am hoping to find a creative RegExp pattern that I could use to parse it in a better way.
Thanks,