Hello ,
What I need to implement is to
find patterns in a string , store matches replace the matches with unique tokens so that later on the token could be replaced by its match found earlier.
To explain
for eample I have an array of patterns
paterns = [/Mr\.\s/,/Mrs\.\s/];
stringSubject = "Mr. john is an expert. mrs. john is no less. mr. watson know this very well";
after extracting matches it might look like (case insensitive match)
stringSubject = "{1} john is an expert. {2} john is no less. {3} watson know this very well";
and the tokens array might look like
tokens = ["Mr.","mr.","mrs."]
stringSubject = "{1} john is an expert. {3} john is no less. {2} watson know this very well";
// after processing stringSubject
tokens are replaced such that
stringSubject = "Mr. john is an expert. mrs. john is no less. mr. watson know this very well";
so that the original string is retrieved as it is even after performing case insensitive operation for matching patterns.
How can this be done with regex ?