简单教程
提交运行
代码编辑器:
<!DOCTYPE html> <meta charset="utf-8"> <title>正则表达式 | 简单教程 (www.twle.cn)</title> <script> var str = "https://www.twle.cn:80/yufei/html/html-basic-index.html"; var patt1 = /(\w+):\/\/([^/:]+)(:\d*)?([^# ]*)/; arr = str.match(patt1); for (var i = 0; i < arr.length ; i++) { document.write(arr[i]); document.write("<br>"); } </script>
运行结果: