亚洲国产日韩欧美一区二区三区,精品亚洲国产成人av在线,国产99视频精品免视看7,99国产精品久久久久久久成人热,欧美日韩亚洲国产综合乱

?????? ???

?? ???(??: ?? ???, ?? ???? regex, regexp ?? RE? ???)? ?? ???? ???? ?? ?? ??? ??? ??? ??? ?? ??? ???? ??????.

??? ?? ? ??? ??? ??? ? ?? ?? ?????.


?? ????? ??????

?? ???? ??? ??? ??? ?? ?????.

????? ???? ??? ? ?? ??? ???? ????? ??? ??? ? ????.

?? ???? ??? ??? ?? ?? ? ??? ??? ?? ????.

???? ?? ??? ?? ? ??? ??? ??? ??? ? ????.

??

/pattern/modifiers;

?:

var patt = /phpl/i

?? ??:

/php/i? ?? ??????.

php? ?????(??? ???).

i? ??????(??? ????? ???? ????).


??? ??? ??

JavaScript?? ???? ????? ? ?? ??? ???, search() ? ???()? ?????.

search() ???? ????? ??? ?? ???? ????? ?? ???? ???? ?? ???? ???? ?? ???? ?? ??? ???? ? ?????.

replace() ???? ???? ?? ??? ?? ??? ???? ???? ???? ?? ???? ??? ? ?????.


search() ???? ???? ?????

?

????? ???? ?? "php.cn" ???? ????? ???? ?????.

<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>PHP中文網(wǎng)(php.cn)</title>
</head>
<body>
<p>搜索字符串 "php.cn", 并顯示匹配的起始位置:</p>
<button onclick="myFunction()">點(diǎn)我</button>
<p id="demo"></p>
<script>
    function myFunction() {
        var str = "Visit php.cn!";
        var n = str.search(/php.cn/i);
        document.getElementById("demo").innerHTML = n;
    }
</script>
</body>
</html>

????? ???? ??? ???.


search() ???? ???? ?????.

?? ???? ???? ????? ??? ? ????. . ??? ????? ?? ????? ?????:

Example

????? "php.cn"? ?? ???? ?????:

<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>PHP中文網(wǎng)(php.cn)</title>
</head>
<body>
<p>搜索字符串 "php.cn", 并顯示匹配的起始位置:</p>
<button onclick="myFunction()">點(diǎn)我</button>
<p id="demo"></p>
<script>
    function myFunction() {
        var str = "Visit php.cn!";
        var n = str.search("php.cn");
        document.getElementById("demo").innerHTML = n;
    }
</script>
</body>
</html>

????? ???? ??? ???


replace() ??? ???? ????? Expression

Example

???? ????? ???? ?? ???? Microsoft? php.cn?? ????.

<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>PHP中文網(wǎng)(php.cn)</title>
</head>
<body>
<p>替換 "microsoft" 為 "php.cn" :</p>
<button onclick="myFunction()">點(diǎn)我</button>
<p id="demo">請(qǐng)?jiān)L問 Microsoft!</p>
<script>
    function myFunction() {
        var str = document.getElementById("demo").innerHTML;
        var txt = str.replace(/microsoft/i,"php.cn");
        document.getElementById("demo").innerHTML = txt;
    }
</script>
</body>
</html>

????? ???? ??? ???


replace() ??? ???

replace() ???? ???? ???? ????? ?????.

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>PHP中文網(wǎng)(php.cn)</title>
</head>
<body>
<p>替換 "Microsoft" 為 "php.cn" :</p>
<button onclick="myFunction()">點(diǎn)我</button>
<p id="demo">請(qǐng)?jiān)L問 Microsoft!</p>
<script>
function myFunction() {
    var str = document.getElementById("demo").innerHTML; 
    var txt = str.replace("Microsoft","php.cn");
    document.getElementById("demo").innerHTML = txt;
}
</script>
</body>
</html>

????? ???? ??? ???.


?:

?? ??? ????? ? ????? ?? ??? ? ????. ??? ????).
???? ?? ??? ?? ???? ????(?: ?/???? ???? ??).


?? ??? ???

???? ?? ???? ????? ??? ? ????.

??? ??
i???? ??- ??? ??.
g ?? ??? ?????(? ?? ?? ??? ?? ? ???? ?? ?? ?? ?? ??).
m?? ? ??? ?????.

?? ??? ??

???? ??? ??? ?? ? ?????.

ExpressionDescription
[abc]??? ?? ??? ?? ??? ????.
[0-9]0?? 9??? ??? ????.
(x|y)|? ??? ??? ????.

?? ??? ??? ??? ?? ?????.

?? ?? Description
d??? ????.
s ?? ??? ????.
b ?? ??? ??????.
uxxxx16?? xxxx? ??? ???? ??? ????.

???:

Quantifier ??
n+? ?? ??? n? ???? ?? ???? ?????.
n*? 0? ??? n? ???? ?? ???? ?????.
n?? 0? ?? 1?? n? ???? ?? ???? ?????.

RegExp ?? ??

JavaScript?? RegExp ??? ?? ??? ??? ???? ?? ??? ?????.


test() ??

test() ???? ??? ??????.

test() ???? ???? ?? ??? ????? ???? ? ?????. ???? ???? ???? ???? ??? true? ???? ??? ??? false? ?????.

?? ?? ????? ?? "e"? ???? ? ?????.

<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>PHP中文網(wǎng)(php.cn)</title>
</head>
<body>
<script>
    var patt1=new RegExp("e");
    document.write(patt1.test("The best things in life are free"));
</script>
</body>
</html>

????? ???? ??? ???


?? ? ?? ??? ??? ??? ??? ??? ????.

/e/ .test("???? ?? ?? ?? ?????!")


exec() ??

exec() ???? ?? ??? ??????. .

exec() ???? ????? ??? ?? ??? ???? ? ?????.

? ??? ???? ??? ???? ??? ?????. ???? ??? ??? ?? ?? null???.

?? ?? ????? ?? "e"? ???? ? ?????.

<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>PHP中文網(wǎng)(php.cn)</title>
</head>
<body>
<script>
    var patt1=new RegExp("e");
    document.write(patt1.exec("The best things in life are free"));
</script>
</body>
</html>

????? ???? ??? ???



???? ??
||
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title>PHP中文網(wǎng)(php.cn)</title> </head> <body> <p>搜索字符串 "php.cn", 并顯示匹配的起始位置:</p> <button onclick="myFunction()">點(diǎn)我</button> <p id="demo"></p> <script> function myFunction() { var str = "Visit php.cn!"; var n = str.search(/php.cn/i); document.getElementById("demo").innerHTML = n; } </script> </body> </html>