We have "getfield" I need "trimfield"
Gurus
This is one of those things you'd think is super simple but I've been pulling my hair out.
There appear to be many ways to trim any occurence of a char/string within another string like a uri but it's always ANY ocurrence.
I want just the FIRST one trimmed. Basically I'm looking for the exact thing "getfield" does except that I wanna trim it when found so
"trimfield" ? I'd look into regex substitution but I know you should not ever use those if you can help it.
My scenario is simple. I just need to cut the first ocurccence of "/rma/" from a uri as part of a re-direct but the uri contains other instances of this string
later in various forms. Example:
/rma/rma.htm?_flowExecutionKey=_somestring
should become:
/rma.htm?_flowExecutionKey=_somestrin
or:
/rma/rma/something&rma=blalb
should become
/rma/something&rma=blalb
I have a dgl called "trim_left_uri" and I figured trimleft is the way to go so I added the string "/rma/" to the dgl and use the following code:
Check if uri needs left trimming
set field1 [getfield [HTTP::uri] "/" 2]
log local0. "field1 is $field1"
if { [class match /$field1/ equals trim_left_uri] } {
set new_uri [string trimleft [HTTP::uri] /$field1/]
problem is that trims this :
/rma/rma.htm?_flowExecutionKey=_somestring
to this:
/.htm?_flowExecutionKey=_something
I'm looking to trim the string literal "/rma/' not the character class [/rma].
Every other way to do this I've found has the same limitation where it's all or nothing for example "string map" - same issue.
It appears to me the easiest way to solve this would be to say "Split the uri by / and trim field 2" - done.
However, I cannot find such a command. Do I need the old regex subsitution after all ?
In bash that would be :
echo '/rma/rma/rma.htm/rma/flowExecutionKey=_mra' | sed 's%^/rma/\(.\+\)%\/\1%g'
/rma/rma.htm/rma/flowExecutionKey=_mra
--scratching head