The improvement of the regular expression training device

Source: Internet
Author: User
Tags expression regular expression
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)
}



Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.