why the second widget place error

I am use the Widget decorations to replace some text which match the regular expressions
For simplicity my custom wigdet look like ‘AAA’
my regular expression string is ‘\$[a-zA-Z0-9_]+\$’
then I give the editor init value ‘$111$aa$222$’
I think It will performance like AAAaaAAA but I get result like The following picture

my code picture

Below is a print of the console

I really don’t know where is wrong

Interesting. Can you set up a minimal reproduction on https://codemirror.net/try/ and link it here? I’ll take a look.