I'm having a hard time trying to split the string into list using multiple delimiters. I could just split it twice like follows:
myString.split(':')[1].split('.')
However this would look so unelegant. In my head, I'd like to do something like:
myString.split(': | .')
Is that even a thing?
I can think of two ways to do it.
Replace all delimeters with a single delimeter and then split:
- set_fact: my_list="{{ (myString | regex_replace(':|.', ':')).split(':') }}"
Split using regular expression:
- set_fact: mystr="{{ myString | regex_findall('([^:.]+)') }} "
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With