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?

1 Answer 1


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 with array_remove_all()


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.