Forum Discussion
Dharshana_11419
Nimbostratus
Nov 20, 2017findstr - sub string of last occurrence of a character to the end of the string
Hi, Can someone please help me how to find the last occurrence of a character and get a sub string from thereafter to the end of the string using findstr? i.e from XXX-GHDF-12XD45 i need to match 12XD45
Many thanks, Dharshana
- Stanislas_Piro2
Cumulonimbus
set str "XXX-GHDF-12XD45" set sub_str [string range $str [string last "-" $str]+1 end]
or
set str "XXX-GHDF-12XD45" set sub_str [lindex [set str_list [split $str "-"]] [llength $str_list]-1]
- Samir_Jha_52506
Noctilucent
You can use
function also to match the column if the position is known.getfield
Example: XXX-GHDF-12XD45
set eidval {XXX-GHDF-12XD45} set val [getfield $eidval "-" 3]
https://devcentral.f5.com/wiki/irules.findstr.ashx
OR
set spr "XXXA-GHDF-12XD45" set sub_spr [string range $spr [string last "-" $spr]+1 end
- Stanislas_Piro2
Cumulonimbus
I also watched
command but didn't find how to say the last field.getfield
- Samir_Jha_52506
Noctilucent
You are right. I am just capturing position value with getfield function.
- Andy_McGrath
Cumulonimbus
set listOfStr [split "XXX-GHDF-12XD45" "-"] set location [expr {[llength $listOfStr] - 2} set output [lindex $listOfStr $location]
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