Forum Discussion
Gaelle_31283
Nimbostratus
Oct 01, 2008Rewriting uri
Hi,
I'm a newbie and I want to rewrite a uri.
if uri contains uid
then I rewrite uri
else I do nothing.
For example :
rtsp://ip?a=12...
hoolio
Cirrostratus
Oct 01, 2008Hi Gaelle,
A string operation would be fastest, but I can't think of a way to handle this easily with just string commands. A regex would provide more flexibility, but cost more in CPU usage. You can use regsub to match the uid=value and replace it with nothing. Here are a few example regexes.
If you don't know what characters the UID can contain, match any character following uid= that isn't an & or new line:
uid=[^&^\n]*&?
If you do know which characters the UID can contain, limit the character class (this example is alphanumerics only:
uid=[a-zA-Z0-9]*&?
If the uid parameter name can be mixed case, replace "uid" with:
[uU][iI][dD]
If you know how long the uid value can be, you can replace * with {0,100} in the above examples, where 0 is the shortest length and 100 is the longest:
uid=[a-zA-Z0-9]{0,100}&?
Of these examples, the most efficient regex would be uid=[a-zA-Z0-9]{0,100}&?
Here are some test cases for the URI with the matches in bold:
?uid=test¶m=value
?uid=¶m=value
?param=value&uid=test¶m=value
?param=value&uid=¶m=value
?param=value&uid=test
?param=value&uid=
To use the regex, you can use regsub:
regsub $regex $source_string $replacement_string
So this command:
regsub {uid=[a-zA-Z0-9]{1,100}&?} {?param=value&uid=test¶m=value} ""
Returns:
?param=value¶m=value
Aaron
Recent Discussions
Related Content
DevCentral Quicklinks
* 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
Discover DevCentral Connects