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的更多相关文章

  1. PCRE Perl Compatible Regular Expressions Learning

    catalog . PCRE Introduction . pcre2api . pcre2jit . PCRE Programing 1. PCRE Introduction The PCRE li ...

  2. 转载:邮箱正则表达式Comparing E-mail Address Validating Regular Expressions

    Comparing E-mail Address Validating Regular Expressions Updated: 2/3/2012 Summary This page compares ...

  3. Regular Expressions --正则表达式官方教程

    http://docs.oracle.com/javase/tutorial/essential/regex/index.html This lesson explains how to use th ...

  4. 正则表达式(Regular expressions)使用笔记

    Regular expressions are a powerful language for matching text patterns. This page gives a basic intr ...

  5. 8 Regular Expressions You Should Know

    Regular expressions are a language of their own. When you learn a new programming language, they're ...

  6. 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 ...

  7. [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 ...

  8. Introducing Regular Expressions 学习笔记

    Introducing Regular Expressions 读书笔记 工具: regexbuddy:http://download.csdn.net/tag/regexbuddy%E7%A0%B4 ...

  9. [转]8 Regular Expressions You Should Know

    Regular expressions are a language of their own. When you learn a new programming language, they're ...

随机推荐

  1. wpf-DataTemplate应用

    在WPF中,决定数据外观的是DataTemplate,即DataTemplate是数据内容的表现形式,一条数据显示成什么样子,是简单的文本还是直观的图形,就是由DataTemplate决定的.下面通过 ...

  2. mvc自带的异步表单提交

    using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.We ...

  3. JavaScript原型,原型链 !

    js原型 问题:什么是js原型? js每声明一个function,都有prototype原型,prototype原型是函数的一个默认属性,在函数的创建过程中由js编译器自动添加. 也就是说:当生产一个 ...

  4. Linux CentOS PhpMyAdmin安装

    安装好PHP,Apache和MySQL程序后,为了管理MySQL数据库,我们需要安装phpMyAdmin程序.下面是关于如何在centos安装phpMyAdmin程序的方法.1.管理员root身份登录 ...

  5. iOS9新特性之UIStackView

    同iOS以往每个迭代一样,iOS 9带来了很多新特性.UIKit框架每个版本都在改变,而在iOS 9比较特别的是UIStackView,它将从根本上改变开发者在iOS上创建用户界面的方式.本文将带你学 ...

  6. angularjs某些指令在外部作用域继承并创建新的子作用域引申出的“值复制”与“引用复制”的问题

    <!DOCTYPE html> <html lang="zh-CN" ng-app="app"> <head> <me ...

  7. (一)HTML5 - pushState 无刷新更新地址

    可以解决什么问题: 可以实现网页的ajax加载,同时又能完成URL的改变而没有网页跳转刷新的迹象,就像是改变了网页的hash(#)一样. 优于hash: 避免了改变hash的问题,避免了用户不理解UR ...

  8. php 练习一 5月5日

    练习题一:通过登录者找到他的好友并显示在页面上 <title>无标题文档</title> <style type="text/css"> * { ...

  9. 超实用--删除MYSQL中指定的数据的全部表

    作过的人都知道,重复测试数据库的苦恼. 用法:# Usage: ./script user password dbnane mysql.nixcraft.in ~~~~~~~~~~~~~ #!/bin ...

  10. Codeforces 573B Bear and Blocks

    http://codeforces.com/problemset/problem/573/B  题目大意: 给出n个连续塔,每个塔有高度hi,每次取走最外层的块,问需要多少次操作能够拿光所有的块. 思 ...