I want to use QGIS expressions to split up a text string to an array with each element representing one character of the input's string, like:
input: mytext
-> ouput: [ 'm', 'y', 't', 'e', 'x', 't' ]
I tried regular expressions with regexp_matches()
function, but was not able to achieve it but partially:
regexp_matches( ('mytext'),'(.+)(.)(.+)') -> [ 'myte', 'x', 't' ]
I could, of course, use the same numer of capturing group (.)
as the input has characters. But the goal is an expression that works with any number of characters. How to achieve that?
Best Answer
Don't think so complicated ;)
Result:
[ 'm', 'y', 't', 'e', 'x', 't' ]
.For some reason
string_to_array()
adds empty stuff (''
) to the array as first and last position, so we remove it witharray_remove_all()