liz_mm50:Language: JavaScript ECMA-262 regular expressions
Appreciate any feedback, or any other language implementation is fine too (i.e. PCRE, VBScript)
thanks.
FYI: Regexes are not portable in many cases. Some regexes written for one language won't work at in another. In many cases the syntax is different. That's why we ask you to tell us which language you are working with in
the Posting Guidelines. Perfect example Sergei's pattern uses a feature unsupported by JavaScript, but since you asked you got a pattern that wouldn't work as written in your target language. While the difference is minor and easy to fix if you know what you are looking for it is still easy to overlook.
I assumed L# was actually part of the input. If not simply remove them from the pattern.
Raw Match Pattern:
(L1.*?\x22([^\x22]+)\x22.*\s^L2
)(.*\s^L3 )(.*\s^L4 )(.*?\s)
Raw Replace Pattern:
$1$2 $3$2 $4$2 $5
Javascript Code Example:
<script
type="text/javascript">
var re
= /(L1.*?\x22([^\x22]+)\x22.*\s^L2
)(.*\s^L3 )(.*\s^L4 )(.*?\s)/m;
var
sourcestring = "source string to match with pattern";
var
replacementpattern = "$1$2 $3$2 $4$2 $5";
var
result = sourcestring.replace(re,
replacementpattern);
alert("result
= " + result);
</script>
$sourcestring after replacement:
L1 Authors name is ="Replimoi"
L2 Replimoi wrote the book of all books
L3 Replimoi painted the childrens illustration chart
L4 Replimoi coded the biomechanical ultimate progy
L5 run out of books
Michael
"In theory, theory and practice are the same. In practice, they are not."
Albert Einstein