[Regular Expressions] Introduction
var str = "Is this This?";
//var regex = new RegExp("is", "gi");
var regex = /is/gi;
//console.log(regex.test(str));
console.log(regex.exec(str)); //["Is", index: 0, input: "Is this This?"]
console.log(regex.exec(str)); //["is", index: 5, input: "Is this This?"]
console.log(regex.exec(str)); //["is", index: 10, input: "Is this This?"]
console.log(regex.exec(str)); //null
console.log(str.match(regex)); //["Is", "is", "is"]
console.log(str.replace(regex, "XX")); //"XX thXX ThXX?"
console.log(str.search(regex)); // 0, return the first index that found
-----------------------------
App:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Javascript Regular Expressions: Introduction</title>
<style>
pre {
line-height: 2;
} span {
background-color: #eee;
padding: 1px;
outline: 1px solid #999;
} </style>
</head>
<body>
<pre></pre>
</body>
</html>
'use strict';
const output = (str, regex, target) => {
target.innerHTML =
str.replace(regex, str => `<span>${str}</span>`);
}
var str = `Is this This?`;
//var regex = new RegExp("is", "g");
var regex = /is/gi;
output(str, regex, document.querySelector('pre'))
// console.log(regex.test(str));
// console.log(regex.exec(str));
// console.log(regex.exec(str));
// console.log(regex.exec(str));
// console.log(regex.exec(str));
// console.log(str.match(regex));
// console.log(str.replace(regex, str => "XX"));
// console.log(str.search(regex));

[Regular Expressions] Introduction的更多相关文章
- PCRE Perl Compatible Regular Expressions Learning
catalog . PCRE Introduction . pcre2api . pcre2jit . PCRE Programing 1. PCRE Introduction The PCRE li ...
- 转载:邮箱正则表达式Comparing E-mail Address Validating Regular Expressions
Comparing E-mail Address Validating Regular Expressions Updated: 2/3/2012 Summary This page compares ...
- Regular Expressions --正则表达式官方教程
http://docs.oracle.com/javase/tutorial/essential/regex/index.html This lesson explains how to use th ...
- 正则表达式(Regular expressions)使用笔记
Regular expressions are a powerful language for matching text patterns. This page gives a basic intr ...
- 8 Regular Expressions You Should Know
Regular expressions are a language of their own. When you learn a new programming language, they're ...
- Regular Expressions in Grep Command with 10 Examples --reference
Regular expressions are used to search and manipulate the text, based on the patterns. Most of the L ...
- [Regular Expressions] Find Plain Text Patterns
The simplest use of Regular Expressions is to find a plain text pattern. In this lesson we'll look a ...
- Introducing Regular Expressions 学习笔记
Introducing Regular Expressions 读书笔记 工具: regexbuddy:http://download.csdn.net/tag/regexbuddy%E7%A0%B4 ...
- [转]8 Regular Expressions You Should Know
Regular expressions are a language of their own. When you learn a new programming language, they're ...
随机推荐
- springmvc中项目启动直接调用方法
1. <servlet> <servlet-name> AutoServlet </servlet-name> <servlet-class> com. ...
- USB通讯协议之深入理解
0. 基本概念 一个[传输](控制.批量.中断.等时):由多个[事务]组成: 一个[事务](IN.OUT.SETUP):由一多个[Packet]组成. USB数据在[主机软件]与[USB设备特定的端点 ...
- 关于一个下载的源代码中的”*.vssscc“文件的问题
今天下载了一份程序的源代码,老是提示我要连接源代码管理服务器,这个……你的账号密码我怎么知道,有木有.于是上网搜罗了一番找来了解决方案,在这里分享给可能出现同样问题的童鞋. 首先说明一下什么是vsss ...
- 使用Gird++打印出现“Retrieving the COM class factory for component with CLSID”的解决办法
我们的接口需要返回一个gird++生成PDF文件的二进制数据,在本地测试都很好,发布到服务器上一直出现“Retrieving the COM class factory for component w ...
- 今天工作中遇到的根据用户id取得产品大类和相关小类的问题
今天做了一个项目,需求是客户登陆后,可以从会员中心发布详细信息(包括联系信息和公司信息),插入到数据库后在将来生成一个公司页面模板,一般的产品大类+小类 用repeater嵌套就可以了,但是这个涉及到 ...
- 记一次lnmp环境下无法执行php文件
lnmp环境搭建好后却无法正常执行php文件,坑爹啊!~ [错误状况] 页面直接打印出php代码内容: php文件无法执行?: 查看nginx配置文件: server { listen 80; ser ...
- PagerSlidingTabStrip的使用
布局 <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:too ...
- C3P0连接池配置方式
c3p0的配置方式分为三种,分别是 1.setters一个个地设置各个配置项 2.类路径下提供一个c3p0.properties文件 3.类路径下提供一个c3p0-config.xml文件 1.set ...
- 关于Xcode7的HTTP请求不到网络的问题
---恢复内容开始--- Xcode7发现网络请求失败, 其他一切都可以, 有网就是提示没有网络, 请求不到, 查询得知 iOS9引入了新特性 APP Transport Security (ATS: ...
- HTML常见标签学习与笔记总结
HTML其实就是把页面的数据封装并加上标签 表头<head> <title> 浏览器标题栏显示的内容 <base> 有href和target属性,href指定网页中 ...