Efficient regular expression to detect 3 attributes in URL
Hello community,
First of all thanks for your time reading and answering this post:
We have read the following topics:
https://docs.intersystems.com/irislatest/csp/docbook/DocBook.UI.Page.cls...
https://community.intersystems.com/post/using-regular-expressions-cach%C...
https://docs.intersystems.com/irislatest/csp/documatic/%25CSP.Documatic....
https://community.intersystems.com/post/string-manipulation
https://community.intersystems.com/post/string-manipulation
We have the following need:
There is an URL which has 3 parameters:
[URL REST]/ServiceRequest?[EXTERNAL HEALTH CENTER CODE]:authoredOn=ge[START DATE RANGE (GREATER THAN OR EQUAL TO)]:authoredOn=le[END DATE RANGE (LESS THAN OR EQUAL TO)]
A real example is:
http://IP:19XXX/ServiceRequest?1111111111:authoredOn=ge2022-01-10:authoredOn=le2022-01-13
However, the health centers may interchange the order of the date attributes:
[URL REST]/ServiceRequest?[EXTERNAL HEALTH CENTER CODE]:authoredOn=le[END DATE RANGE (LESS THAN OR EQUAL TO)]:authoredOn=ge[START DATE RANGE (GREATER THAN OR EQUAL TO)]
Being a real example:
http://IP:19XXX/ServiceRequest?1111111111:authoredOn=le2022-01-13:authoredOn=ge2022-01-10
We have thought about the following rudimentary logic to obtain the 3 attributes:
set externalCenterCode = $PIECE($PIECE(url, :authoredOn=, 1) , /ServiceRequest? , 2)
set startDateRange = $PIECE($PIECE( url, :authoredOn=ge, 2) , :authoredOn=le , 1)
set endDateRange = $PIECE($PIECE( url, :authoredOn=le, 2) , :authoredOn=ge , 1)
📌📍 Is there a more readable, understandable, simple and correct way using regular expressions to obtain the 3 attributes?
We would be grateful if you could provide us with documentation, manuals, examples, references, explanations or any other means and/or tool that would allow us to solve this need in the most understandable, legible and correct way possible.
Thank you in advance
Best regards
We ask you because you are more experimented, skilled and you have more familiarity with ObjectScript and Ensemble.
In addition we have checked that the previous sentence:
set startDateRange = $PIECE($PIECE( url, ":authoredOn=ge", 2) , ":authoredOn=le", 1)
Would fail when ge is at the ending as in the following url:
set url = "http://IP:19XXX/ServiceRequest?1111111111:authoredOn=le2022-01-13:author..."
Plus, it would fail in the next line:
set endDateRange = $PIECE($PIECE( url, ":authoredOn=le", 2) ," :authoredOn=ge" , 1)
When le is at the ending, in the URL:
set url = "http://IP:19XXX/ServiceRequest?1111111111:authoredOn=ge2022-01-10:author..."
🔘 Could you help us please?
Thank you in advance
Best regards