I have following string from which i expect to replace the first two occurrences of <br>
with a \n
character.
<br><br><br>. Do not replace <br> here.
1. One
2. Two
3. Three<br><br><br>End of List. Replace first two <br> with \n
New line follows.
<br><br><br>. Do not replace <br> here.
I did write my regex here. I am very new to regex and i am sure this is not an optimized solution. After some tries i was able to select the <br><br>
as a capturing group. I want this 3rd capturing group to be my selected match so i can easly replace it with \n
. Can someone help me with this?
My expected output is:
<br><br><br>. Do not replace <br> here.
1. One
2. Two
3. Three\n<br>End of List. Replace first two <br> with \n
New line follows.
<br><br><br>. Do not replace <br> here.
var str = `1. One
2. Two
3. Three<br><br><br>End of List
New line follows
`
console.log(
str.match(/[\n\r].*(\d\.\s+)(?!.*[\n\r](\d\.\s+)).*((<br\s*\/?>){2})/)
);
Try this.
let str = `<br><br><br>. Do not replace <br> here.
1. One
2. Two
3. Three<br><br><br>End of List. Replace first two <br> with \n
New line follows.
<br><br><br>. Do not replace <br> here.`;
console.log(str.replace(/(?<=[0-9]+\..*?)(<br>){2}/g, "\n"));
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments