欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

正則表達(dá)式練習(xí)器

 更新時(shí)間:2006年06月17日 00:00:00   作者:  
復(fù)制代碼 代碼如下:

<HTML>
<HEAD>
<TITLE>正則表達(dá)式練習(xí)器</TITLE>
<meta name = 安徽 池州 統(tǒng)計(jì)局 徐祖寧 e-mail:czjsz@stats.gov.cn>
<script language="JavaScript">
function OnMove() {
window.status = "("+window.event.clientX+","+window.event.clientY+")" + " :: "+document.location
}
</script>

<SCRIPT LANGUAGE="JavaScript1.2">
var re = new RegExp() //建立正則表達(dá)式對(duì)象
var nextpoint = 0 //匹配時(shí)的偏移量
//設(shè)置正則表達(dá)式
function setPattern(form) {
var mode
if(form.chkmode.checked) mode = "gi" //i:不分大小寫(xiě) g:全局,好象沒(méi)什么作用
else mode = "g"
re.compile(form.regexp.value,mode)
nextpoint = 0
form.reglist.value = ""
}
//檢查是否有匹配
function findIt(form) {
setPattern(form)
var input = form.main.value
if (input.search(re) != -1) {
form.output[0].checked = true
} else {
form.output[1].checked = true
}
}
//檢查匹配位置
function locateIt(form) {
setPattern(form)
var input = form.main.value
form.offset.value = input.search(re)
}
//檢查所有的匹配情況
function execIt(form) {
if(nextpoint == 0 || ! form.scankmode.checked) {
findIt(form)
form.reglist.value = ""
}
var key = true
if(form.scankmode.checked) key = false
do {
var input = form.main.value
var matchArray = re.exec(input.substr(nextpoint))
if(matchArray) {
for(var i=1;i<matchArray.length;i++)
matchArray[i] = "$"+i+":"+matchArray[i]
form.reglist.value = (nextpoint+matchArray.index)+" => " + matchArray[0] +"\n"+form.reglist.value
form.matchlist.value = "$0:"+matchArray.join("\n")
nextpoint = nextpoint + matchArray.index + matchArray[0].length
}else {
if(!key)
form.reglist.value = "沒(méi)有找到\n" + form.reglist.value
form.matchlist.value = " "
nextpoint = 0
key = false
}
}while (key)
}
//設(shè)置當(dāng)前使用的正則表達(dá)式
function setregexp(n) {
var s = document.all.regexplist.value.split("\r\n")
document.all.regexp.value = s[n*2-1] //.replace("\r","")
nextpoint = 0
}

//定義選擇監(jiān)視
var isNav = (navigator.appName == "Netscape")
function showSelection() {
if (isNav) {
var theText = document.getSelection()
} else {
var theText = document.selection.createRange().text
}
if(theText.length>0 && document.all.selechkmode.checked)
document.all.regexp.value = theText
}
if (isNav) {
document.captureEvents(Event.MOUSEUP)
}
document.onmouseup = showSelection
</SCRIPT>

</HEAD>
<BODY style="font-size=9pt;" OnMouseMove=OnMove()>
<FORM><table width=100% cellspacing=0 cellpadding=0><tr><td><font color=red>正規(guī)表達(dá)式練習(xí)器</font></td><td align=right><a href=mailto:czjsz_ah@stats.gov.cn>czjsz_ah@stats.gov.cn</a></td></tr></table>
<table width=100% broder=1 frame=above rules=none style="font-size:9pt;">
<tr><td width=50% valign=top>
輸入一些被尋找的正文:<BR>
<TEXTAREA NAME="main" COLS=58 ROWS=5 WRAP="virtual" style="font-size:9pt;">
09-11-2001 09/11/2001 czjsz_ah@stats.gov.cn
asdff 12345 196.168.1.3 www.sohu.com ftp://www.chinaasp.com 2001.9.11 http://www.active.com.cn/club/bbs/bbsView.asp http://www.163.com/inden.htm
</TEXTAREA><BR>
進(jìn)行匹配的正規(guī)表達(dá)式:  忽略大小寫(xiě)<INPUT TYPE="checkbox" NAME="chkmode" checked style="font-size:8pt;height:18px"><BR>
<TEXTAREA NAME="regexp" COLS=51 ROWS=5 style="font-size:9pt;"></TEXTAREA>
<INPUT TYPE="button" VALUE="清除" onClick="this.form.regexp.value=''" style="font-size:8pt;height:18px"><BR>
<INPUT TYPE="button" VALUE="能找到嗎?[regexObject.test(string)]" style="font-size:8pt;width:70%;height:18px" onClick="findIt(this.form)">
<INPUT TYPE="radio" NAME="output" style="font-size:8pt;height:18px">Yes
<INPUT TYPE="radio" NAME="output" style="font-size:8pt;height:18px">No <BR>
<INPUT TYPE="button" VALUE="在哪里?[string.search(regexObject)]" style="font-size:8pt;width:70%;height:18px" onClick="locateIt(this.form)">
<INPUT TYPE="text" NAME="offset" SIZE=4 style="font-size:8pt;height:18px">
</td>
<td valign=top>
測(cè)試用正則表達(dá)式列表: 
使用第<input type=text name=num size=2 value=1 style="font-size:8pt;height:18px">個(gè)<input type=button value=Go onClick=setregexp(this.form.num.value) style="font-size:8pt;height:18px">
    允許復(fù)制<INPUT TYPE="checkbox" NAME="selechkmode" style="font-size:8pt;height:18px">
<textarea NAME="regexplist" cols=58 rows=14 wrap=off style="font-size:9pt;">
1.檢查日期:
(1[0-2]|0?[1-9])[-./](0?[1-9]|[12][0-9]|3[01])[-./](\d\d\d\d))
2.檢查數(shù)字:
([-+]?[0-9]+\.?[0-9]+)
3.檢查URL:
((http|ftp)://)?(((([\d]+\.)+){3}[\d]+(/[\w./]+)?)|([a-z]\w*((\.\w+)+){2,})([/][\w.~]*)*)
4.檢查E-mail
\w+@((\w+[.]?)+)
</textarea>
</td></tr>
<tr><td valign=bottom>
<INPUT TYPE="button" VALUE="有哪些?[regexObject.exec(string)]" style="font-size:8pt;width:70%;height:18px" onClick="execIt(this.form)">
  單步<INPUT TYPE="checkbox" NAME="scankmode" style="font-size:8pt;height:18px"><BR>
<TEXTAREA NAME="reglist" COLS=58 ROWS=8 style="font-size:9pt;"></TEXTAREA>
</td>
<td valign=bottom>
匹配到的成分:(單步時(shí)可見(jiàn))
<TEXTAREA NAME="matchlist" COLS=58 ROWS=8 style="font-size:9pt;"></TEXTAREA>
</td></tr></table></FORM>
<script>
setregexp(1)
</script>
</BODY>
</HTML>


對(duì)正則表達(dá)式練習(xí)器的改進(jìn),原貼ID901680

覆蓋原execIt函數(shù)
修改后的execIt函數(shù)允許對(duì)多個(gè)正則表達(dá)式進(jìn)行匹配(每個(gè)正則表達(dá)式一行),并對(duì)每一個(gè)匹配成分顯示出是第幾個(gè)正則表達(dá)式匹配的。
這可視為語(yǔ)法分析的雛形,只要對(duì)匹配產(chǎn)生相應(yīng)的動(dòng)作。

function execIt(form) {
var mode
if(form.chkmode.checked) mode = "gi"
else mode = "g"
var regexpArray = form.regexp.value.split("\r\n") //獲取正則表達(dá)式到數(shù)組

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)
//對(duì)每個(gè)正則表達(dá)式進(jìn)行匹配
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 //保存距離起始位子最近的匹配
}
}
}
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 = "$0:"+matchArray.join("\n")
nextpoint = nextpoint + matchArray.index + matchArray[0].length
}else {
if(!key)
form.reglist.value = "沒(méi)有找到\n" + form.reglist.value
form.matchlist.value = " "
nextpoint = 0
key = false
}
}while(key)
}

相關(guān)文章

  • js正則表達(dá)式中的問(wèn)號(hào)幾種用法小結(jié)

    js正則表達(dá)式中的問(wèn)號(hào)幾種用法小結(jié)

    這篇文章主要介紹了js正則表達(dá)式中的問(wèn)號(hào)幾種用法,比如+?,*?,{2,3}?可以停止匹配的貪婪模式,感興趣的朋友可以參考下
    2014-09-09
  • VBS中的正則表達(dá)式的用法大全

    VBS中的正則表達(dá)式的用法大全

    這篇文章主要為大家介紹下VBS中的正則表達(dá)式的一些使用方法,需要的朋友可以參考下
    2006-10-10
  • 一篇文章了解正則表達(dá)式的替換技巧

    一篇文章了解正則表達(dá)式的替換技巧

    正則表達(dá)式非常有用,查找、匹配、處理字符串、替換和轉(zhuǎn)換字符串,輸入輸出等,下面這篇文章主要給大家介紹了關(guān)于正則表達(dá)式替換技巧的相關(guān)資料,需要的朋友可以參考下
    2022-02-02
  • notepad、editplus等軟件常用的文本整理正則表達(dá)式

    notepad、editplus等軟件常用的文本整理正則表達(dá)式

    這篇文章主要介紹了notepad、editplus等軟件常用的文本整理正則表達(dá)式,本文講解了匹配空行、所有空行、空格、換行、2個(gè)以上的空格等正則,需要的朋友可以參考下
    2015-04-04
  • 教你輕松記住JS正則表達(dá)式

    教你輕松記住JS正則表達(dá)式

    有沒(méi)有人像小編一樣,學(xué)了好幾遍正則表達(dá)式卻還是很懵圈,學(xué)的時(shí)候老明白了,學(xué)完了忘光了。好吧,其實(shí)還是練的不夠,今天就隨我來(lái)復(fù)習(xí)一下這傲嬌的正則表達(dá)式吧。
    2016-07-07
  • 正則表達(dá)式 口訣 學(xué)習(xí)正則的朋友看看

    正則表達(dá)式 口訣 學(xué)習(xí)正則的朋友看看

    非常不錯(cuò)的口訣,相信學(xué)習(xí)正則的朋友感覺(jué)入門很難,其實(shí)并不是想象中的難,你看下面不知道是哪位高手整理的口訣,看口訣就知道此人對(duì)正則的熟練程度非常高了。
    2009-04-04
  • 常用正則表達(dá)式 比較實(shí)用

    常用正則表達(dá)式 比較實(shí)用

    正則表達(dá)式用于字符串處理、表單驗(yàn)證等場(chǎng)合,實(shí)用高效?,F(xiàn)將一些常用的表達(dá)式收集于此,以備不時(shí)之需。
    2009-03-03
  • php 正則表達(dá)式學(xué)習(xí)筆記

    php 正則表達(dá)式學(xué)習(xí)筆記

    最近在學(xué)習(xí)正則,一些比較有用的東西怕忘記,記下來(lái),比較亂,想一條記錄一條:
    2008-06-06
  • shell腳本中的正則表達(dá)式詳解

    shell腳本中的正則表達(dá)式詳解

    正則表達(dá)式是通過(guò)一些特殊字符的排序,用以刪除、查找、替換一行或者多行文字字符串的程序,本文給大家介紹shell腳本正則表達(dá)式的相關(guān)知識(shí),感興趣的朋友一起看看吧
    2021-07-07
  • 正則表達(dá)式(簡(jiǎn)單易懂篇)

    正則表達(dá)式(簡(jiǎn)單易懂篇)

    正則表達(dá)式是一種可以用于模式匹配和替換的強(qiáng)大工具。這篇文章主要介紹了正則表達(dá)式(簡(jiǎn)單易懂篇),需要的朋友參考下
    2017-01-01

最新評(píng)論