简体   繁体   中英

React multiple occurrences replace using regular expression

I've been trying to replace patterned occurrences from copy pasted 24 page string from PDF, to create array of collected substrings in react.js. The format is as follows:

    var result = /(?<= startpoint)(.*)(?=endpoint)/g;

Due to the fact that symbols are included in the string, I am trying to delete '/' symbols from above result.

    var symbremoved = result.replace(/[/]/, "");

Yet I get an error saying result.replace is not a function.

Is there a rule that patterned Regular Expressions I have to follow?

I learned as I'm doing, but the problem is that your result is not a string, and replace is a string method.

You have to use myString.replaceAll(/myRegex/g, "") , the g is important, as you can see in the print bellow.

在此处输入图像描述

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM