Jump to content
  • Hello visitors, welcome to the Hacker World Forum!

    Red Team 1949  (formerly CHT Attack and Defense Team) In this rapidly changing Internet era, we maintain our original intention and create the best community to jointly exchange network technologies. You can obtain hacker attack and defense skills and knowledge in the forum, or you can join our Telegram communication group to discuss and communicate in real time. All kinds of advertisements are prohibited in the forum. Please register as a registered user to check our usage and privacy policy. Thank you for your cooperation.

    TheHackerWorld Official

java script 日常学习 正则表达式

 Share


NedK7

Recommended Posts

 

<!DOCTYPE html>
<html>
<head>
<title>函数的运用</title>
<meta charset="utf-8">
</head>
<body>

<script type="text/javascript">
/*
//使用字符串的正则表达式方法
//var box = new RegExp('box','ig')
var box = /box/ig;
var ik = "this is a box !";
//alert (ik.match(box)); //上面有几个box就弹出几个
//alert (ik.match(box).length); //获取到了几个
//alert (ik.search(box)); //seatch 找到box中的box的b在第几个位置
//alert (ik.replace(box,'Tom')); //replace替换 瑞普利似
//alert (ik.split(box)); //split分开 以box将字符串以数组的型试分开

//正则表达式对象的静态属性
var box = new RegExp('(i)fhsik','ig'); //出现问题:忘记打了个new
var ik = "har are you , my name is ifhsik !";
box.test(ik); //出现问题:将test打成了text
//alert(RegExp.input); //找到指定位置原样输出 $_
//alert(RegExp.leftContext); //找到指定位置的左边 $`
//alert(RegExp.rightContext); //找到指定位置的右边 左右这两个条件除本身不显示出来 $'
//alert(RegExp.lastMatch); //最后一个匹配的字符串 $&
//alert(RegExp.lastParen); //最后一对圆括号内的匹配子串 $+
*/

</script>
</body>
</html>

Link to post
Link to comment
Share on other sites

 Share

discussion group

discussion group

    You don't have permission to chat.
    • Recently Browsing   0 members

      • No registered users viewing this page.
    ×
    ×
    • Create New...