iansinnott / react-string-replace

A simple way to safely do string replacement with React components
MIT License
652 stars 56 forks source link

I have a problem with '/r' in text. It not working '/r' #82

Open RinNguyens opened 2 years ago

RinNguyens commented 2 years ago

code-problem

result : reactStringReplace output not working '/r' in array[2] image above results

tchajed commented 1 year ago

My guess (because I had the same bug) is that you need to use a capturing group in your regex:

  let el = reactStringReplace(el, /(\n)/g, (_match, i) => <br key={i} />);

Note the use of /(\n)/g rather than just /\n/g.