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
Can you add support for multiple regex capture groups?
With a bit of a workaround you could the the matcher do the logic. The caveat being that the matcher regex, cannot be the same as the "parser" regex, reason being that str.split splits on capture group.
constmd=`[Test](https://google.com)`;// Pay attention to where the matcher and parser group diffsreactStringReplace(md,/(\[.*?\]\(.*?\))/gi,(match,index)=>{match.match(/\[(.*?)\]\((.*?)\)/gi);return<ahref={RegExp.$2}>{RegExp.$1}</a>});
Reacted by Theo Stavrides, konstantinhenke and NexusDeveloper
Speaking of, is there any legitimate way to render html containing markdown? I'm using react-string-replace to highlight some text in a string, but now I've been asked to also render any markdown contained in the string. The way I reeive the data means that the highlight-replacement must operate on the string, so I have to do that part first. If the original string contained markup, I'm left with something like the following (in array form, of course)
This is <span className="yellow">highlighted</span> text but it has some ## markup as well
If it was a raw string, I could just use react-markdown or similar lib, but obviously that's not an option after the first transform.
Any ideas? Even if it means combining with a different package? Btw thanks so much, this library is awesome
Activity
iansinnott commentedon Apr 21, 2020
Do you have an example regex?
This library depends on the functionality of
String.prototype.splitwhich will place matched characters in odd-numbered elements of a split array:hejrobin commentedon Dec 1, 2020
With a bit of a workaround you could the the matcher do the logic. The caveat being that the matcher regex, cannot be the same as the "parser" regex, reason being that str.split splits on capture group.
oneillsp96 commentedon Jan 8, 2021
Speaking of, is there any legitimate way to render html containing markdown? I'm using react-string-replace to highlight some text in a string, but now I've been asked to also render any markdown contained in the string. The way I reeive the data means that the highlight-replacement must operate on the string, so I have to do that part first. If the original string contained markup, I'm left with something like the following (in array form, of course)
This is <span className="yellow">highlighted</span> text but it has some ## markup as wellIf it was a raw string, I could just use react-markdown or similar lib, but obviously that's not an option after the first transform.
Any ideas? Even if it means combining with a different package? Btw thanks so much, this library is awesome
federicocappellotto97 commentedon Mar 9, 2023
Here the example:
"<h1>Lorem <strong>Ipsum</strong> <strong>Dolor</strong></h1>".replace( /(^|<\/?[^>]+>|\s+)([^\s<]+)/g, '$1<span>$2</span>' )