In our product we are trying to parse the following different formats from a given piece of text -
${{node::123456}}${{node:123456}}$fn{{#functionName('abcd',',',' somethingWithASpace')}}$fn{{#functionName('abcd','#','${{node::123456}}')}}${{rmtrqst:someText[]->abcd}}
Sample of the text is like -
Hi, how are you ${{node::123456}}? Your order id is ${{node::636636}}.
or
Your order was placed on $fn{{#dateConverterFunction('abcd','#','${{node::123456}}')}}
I tried with Regex /\$((fn)\{{2}(\#|)(\w*)((\(.*\))|([^\$]*))\}{2})/gi - but this is not helping much. Can anyone suggest me how to write a parser for this?
A grammar could be like this -
- Every expression starts with $ followed by either fn{{ or {{
- After that there will be a string like node or #functionName or something else
- that might be followed by a parenthesis enclosed string (this may contain the whole expression like ${{node::1234}} inside it - we should ignore whatever inside parenthesis
- Finally it will be closed by }}
$followed by eitherfn{{or{{2. After that there will be a string likenodeor#functionNameorsomething else3. that might be followed by a parenthesis enclosed string (this may contain the whole expression like${{node::1234}}inside it - we should ignore whatever inside parenthesis 4. Finally it will be closed by}}${{node