The improvement of the regular expression training device
Source: Internet
Author: User
The improvement of the regular expression practice, 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 ("")//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)
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