[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 ...
随机推荐
- struts2讲义----二
Struts的namespace 示例工程Struts2_0200_Namespace Struts.xml <struts> <constant name="struts ...
- Linux修改SSH连接数 重启SSH服务
系统 linux,增加SSH终端连接数最大为1000个 解决方案: vi /etc/ssh/sshd_config 输入/MaxStartups 定位到如下并修改 1) #MaxStar ...
- 作业三 ATM
模拟实现一个ATM+购物商场程序 1.额度15000自定义 商城和银行两个帐户 2.实现购物商城,买东西加入购物车,调用信用卡接口结账 3.可以提现,手续费5%,提现额度不能超过50% 4.每月22日 ...
- 1:scrapy框架原理与环境搭设
1:原理图: (*此图来自网络) 2:开发过程: 1)编写items.py,确定要抓取的关键字段名称 2)编写spider,确定发送request的形式以及对于response的处理 3)编写pipe ...
- 解决VS2008闪退的问题
问题:打开VS2008项目后,应该是加载完所有文件,立即断掉了IDE,查看事件器,发现图片中的错误描述,google了很久没有找到解决方案,后来还是自己动手解决这个问题花了一早上的时间,哎,只要把工程 ...
- notification:object not locked by thread before notify()
今天写notification练习时,误将NotificationManager.notify(0, notification);写成notification.notify(); 代码如下 publi ...
- 《第一行代码》学习笔记37-服务Service(4)
一个比较完整的自定义AsyncTask写成如下: class DownloadTask extends AsyncTask<Void, Integer, Boolean> { @Overr ...
- RAC的负载均衡有2种方式
RAC的负载均衡有2种方式1:数据库服务器端 设置remote_listener2: 客户端tns配置 一般连接串这么写:ess_hb_i1= (DESCRIPTION = (ADDRESS ...
- 武汉科技大学ACM :1003: 零起点学算法67——统计字母数字等个数
Problem Description 输入一串字符,统计这串字符里的字母个数,数字个数,空格字数以及其他字符(最多不超过100个字符) Input 多组测试数据,每行一组 Output 每组输出一行 ...
- 包装 request Demo
//包装request,增强getParameter方法 class MyReq extends HttpServletRequestWrapper{ private HttpServletReque ...