Forum Discussion
Need to parse the [HTTP::uri] and modify it for a redirect
- Dec 29, 2017
could you please explain what exactly the code is doing especially the regular expression part and the string map ?
/~ is literal chars (i.e. it matches /~)
%[^/] matches every chars but not / and the matching string will be stored in variable specified later (e.g. it matches geverest and geverest will be stored in first variable)
[scan [HTTP::uri] {/~%[^/]} first] returns number of matching string. so, we can use it to determine whether it is uri we are interested (i.e. 1).
[string map "/~$first/ /" [HTTP::uri]] replace /~$first/ with / in uri (e.g. it replaces /~geverest/ with /).
[root@bip1a:Active:In Sync] config tclsh % set uri "/~geverest/home/data-modeling-course/course-flyer" /~geverest/home/data-modeling-course/course-flyer % scan $uri {/~%[^/]} first 1 % put $first geverest % string map "/~$first/ /" $uri /home/data-modeling-course/course-flyer
could you please explain what exactly the code is doing especially the regular expression part and the string map ?
/~ is literal chars (i.e. it matches /~)
%[^/] matches every chars but not / and the matching string will be stored in variable specified later (e.g. it matches geverest and geverest will be stored in first variable)
[scan [HTTP::uri] {/~%[^/]} first] returns number of matching string. so, we can use it to determine whether it is uri we are interested (i.e. 1).
[string map "/~$first/ /" [HTTP::uri]] replace /~$first/ with / in uri (e.g. it replaces /~geverest/ with /).
[root@bip1a:Active:In Sync] config tclsh
% set uri "/~geverest/home/data-modeling-course/course-flyer"
/~geverest/home/data-modeling-course/course-flyer
% scan $uri {/~%[^/]} first
1
% put $first
geverest
% string map "/~$first/ /" $uri
/home/data-modeling-course/course-flyer
Thank you very much - this is incredibly helpful.
Recent Discussions
Related Content
* Getting Started on DevCentral
* Community Guidelines
* Community Terms of Use / EULA
* Community Ranking Explained
* Community Resources
* Contact the DevCentral Team
* Update MFA on account.f5.com