react-native-controlled-mentions
react-native-controlled-mentions copied to clipboard
replaceMentionValues not working with multi mentions inside string
for example i have below string:
@[demo5](d3f0c3cd-f363-4303-8761-8e190f054be3) @[demo8](8dbafd40-b86f-490a-828d-d11dfe221b43) test
then
params.Msg.Text = replaceMentionValues(text, ({name}) => `@${name}`)
result:
@demo5 @[demo8](8dbafd40-b86f-490a-828d-d11dfe221b43) test
I can reproduce this issue. The issue appears only in 3.0.0-alpha.2. It works in 3.0.0-alpha.1.
thanks, @dabakovich plz update the problem
waiting. for @dabakovich confirm
The cause of this issue is located in constraints.ts
in 3.0.0-alpha.2 which defines the following regex: const mentionRegEx = /((.)\[([^[]*)]\(([^(^)]*)\))/i;
. In 3.0.0-alpha.1 the used regex is located in utils.ts
and is as follows: const mentionRegEx = /((.)\[([^[]*)]\(([^(^)]*)\))/gi;
. The delimiter is not global anymore, thus not all words will be matched.
It seems to be fixed in the newest version of the 3.0 branch. The function is renamed to replaceTriggerValues
and adds the g
to the regex. There is a test case in utils.test
. I guess you can either downgrade to alpha 1 or use the newest version of the 3.0 branch (but the matching pattern seems to have changed a little bit).