Reference: Regular expression operations
Breaking down the expression
. - dot ignore newline match all other characters
* - match zero or more repetitions of the proceeding RE
such that "ab*" will match "ab" "abb" "abbbb" etc...
? - match zero or 1 repetitions of the proceeding RE
such that "ab?" it will match "a" or "ab"
So we now have the construct *?
Adding the ? after the * says only match the first instance.
That is to say * by itself will match as many as possible - it's greedy.
*? is not greedy and matches as few as possible.
SO for string="abc"; rex=".*?"; will match only the "a"
Change the expression to - with global and multi set true:
re.sub('.','-','abc')
this should render to ' - - - '
I know that this will render "---" also with global and multi set true:
re.sub('[a-zA-Z0-9]','-','abc')
You need a good primer on Regular Expressions
>I've found this one:
https://www.rexegg.com/
It appears to cover the basics and a bit of extra too.