Bin
Bin

Reputation: 19

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?

Upvotes: 0

Views: 1274

Answers (1)

Jorge Kunrath
Jorge Kunrath

Reputation: 1006

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.

enter image description here

Upvotes: 1

Related Questions