You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
You can run multiple replacements on one string by calling the function multiple times on the returned result. For instance, if we want to match URLs, @-mentions and hashtags in a string we could do the following:
consttext='Hey @ian_sinn, check out this link https://github.com/iansinnott/ Hope to see you at #reactconf';
73
84
let replacedText;
@@ -104,11 +115,11 @@ See the [`example/`](https://github.com/iansinnott/react-string-replace/tree/mas
104
115
105
116
## Why?
106
117
107
-
I wanted an easy way to do string replacement a la`String.prototype.replace` within React components **without** breaking React's built in string escaping functionality. This meant standard string replacement combined with `dangerouslySetInnerHTML` was out of the question.
118
+
I wanted an easy way to do string replacement similar to`String.prototype.replace` within React components **without** breaking React's built in string escaping and XSS protection. This meant standard string replacement combined with `dangerouslySetInnerHTML` was out of the question.
The replacer function to run each time `match` is found. This function will be passed the matching string and an `index` which can be used for adding keys to replacement components if necessary. Character `offset` identifies the position of match start in the provided text.
With v1.0.0 the API is considered stable and should be considered production ready. Pull requests are still welcome but there is currently no intent to make changes to this lib other than bug fixes (please submit an issue if you find something!).
160
+
161
+
For details on API tests see [the tests file](./test.js).
0 commit comments