Forum Discussion
Lucas_Thompson
Feb 07, 2024Employee
It looks like your regex is a little too greedy and is matching the ending curly brace of the vs name.
One universal "how to make simple regexes" approach is to avoid using (.+) which tends to match too much stuff, and using this sort of thing instead: ([^ ]). The square brackets mean "characters in the set of" and caret means "not", so ([^ ]+) means "capture one or more characters that are not a space". This is a safe way to match a value where you know the delimiter beforehand: VSs won't have a space and will always be followed by a space.
So your regex becomes:
if [[ $full_vs_info =~ ltm\ virtual\ ([^\/]+)/([^ ]+) ]]; then
A few other things:
- You can pass an "-p" to get read to give the user a prompt which will make it a little easier to use
- TMSH has a "one-line" argument that tells it to list each config object in its own line to make the kind of text processing you're doing here easier, for example "tmsh list /ltm virtual recursive one-line"