Regular expression of the practice of the improvement, the original paste ID901680
Overwrite the original execit function
The modified EXECIT function allows multiple regular expressions to be matched (one row for each regular expression) and a few regular expression matches for each matching component.
This can be seen as the embryonic form of parsing, as long as the corresponding action is generated for the match.
function execit (form) {
var mode
if (form.chkmode.checked) mode = "GI"
else mode = "G"
var Regexparray = Form.regexp.value.split ("\ r \ n")//Get regular expression to array
if (Nextpoint = = 0) Form.reglist.value = ""
var key = True
if (form.scankmode.checked) key = False
else Nextpoint = 0
do {
var offs = 9999999999
var pos =-1
var input = form.main.value.substr (Nextpoint)
To match each regular expression
for (Var i=0;i<regexparray.length;i++) {
Re.compile (Regexparray[i],mode)
var Matcharray = re.exec (input)
if (Matcharray) {
if (Offs > Matcharray.index) {
Offs = Matcharray.index
pos = I//save the closest match to the starting seat
}
}
}
if (pos>=0) {
Re.compile (Regexparray[pos],mode)
var Matcharray = re.exec (input)
for (Var i=1;i<matcharray.length;i++)
Matcharray[i] = "$" +i+ ":" +matcharray[i]
Form.reglist.value = "[" + (POS+1) + "]" + (Nextpoint+matcharray.index) + "=>" + matcharray[0] + "\ n" +form.reglist.value
Form.matchlist.value = "$:" +matcharray.join ("\ n")
Nextpoint = nextpoint + Matcharray.index + matcharray[0].length
}else {
if (!key)
Form.reglist.value = "Not found \ n" + form.reglist.value
Form.matchlist.value = ""
Nextpoint = 0
Key = False
}
}while (Key)
}