Let's image tow cases for the following string:

var str = `foo
foobar
foobaz
fooboo`

First of all: we know how to capture foobar or fooboo:

var regex = /foo(bar|boo)/g

1: We want to capture any 'foo' which followed by 'bar' or 'boo', but we do NOT want 'bar' or 'boo' appear in our result:

So we can use:

?= 

so:

var regex = /foo(?=bar|boo)/g

2. We want to capture any 'foo' without 'bar' or 'boo' followed:

so we can use:

?!

so:

var regex = /foo(?!bar|boo)/g

[Regular Expressions] Find a String that Precedes Another String ?= , ?!的更多相关文章

  1. PCRE Perl Compatible Regular Expressions Learning

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

  2. 8 Regular Expressions You Should Know

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

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

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

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

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

  6. Introducing Regular Expressions 学习笔记

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

  7. [转]8 Regular Expressions You Should Know

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

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

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

  9. 自学Zabbix8.1 Regular expressions 正则表达式

    点击返回:自学Zabbix之路 点击返回:自学Zabbix4.0之路 点击返回:自学zabbix集锦 自学Zabbix8.1 Regular expressions 正则表达式 1. 配置 点击Adm ...

随机推荐

  1. spring 通过工厂方法配置Bean

    概要: 通过调用静态工厂方法创建Bean 调用静态工厂方法创建Bean是将对象创建的过程封装到静态方法中.当client须要对象时,仅仅须要简单地调用静态方法,而不用关心创建对象地细节. 要声明通过静 ...

  2. Java第四周学习日记

    Day01 双列集合: 在现实生活中有些数据是以映射关系存在的,也就是成对存在的,比如夫妻等.单例集合无法表现出映射关系,所以学习双列集合. 双列集合无迭代器. 1.Map 双列集合: ——————— ...

  3. 编译U-boot时,make[1]: *** 没有规则可以创建mkimage.o”

    执行完make smdk2440_config 对Uboot重行编译怎么会出现这样的错误 make[1]: Entering directory `/home/win/S3-ARM/Part4/ubo ...

  4. HTML基础知识笔记(三)

    HTML下拉列表框 讲解: 1.value: <option value="House Blend">House Blend</option> 2.sele ...

  5. c#类初始化器

    其实类型初始化器只是一种语法糖这样写MyClass a=new MyClass{ filedOne="a" ,filedTwo="b" };会被编译器编译成和如 ...

  6. 高级子查询【weber出品必属精品】

    多列子查询 where条件中出现多列与子查询进行比较 多列子查询分为:成对比较和非成对比较 成对比较: SQL> select ename,sal,job from emp where (dep ...

  7. Scala学习笔记--提取器unapply

    提取器就是一个带有unapply方法的对象.你可以把unapply方法当做是伴生对象中apply方法的反向操作. apply方法接收构造参数,然后将他们变成对象. 而unapply方法接受一个对象,然 ...

  8. SVN上传代码时代码失败

    Description : You are not authorized to access the files in the repository.Suggestion : You might be ...

  9. 利用sql命令把结果集输出到文件

    利用sql命令把结果集输出到文件 红色部分的三条命令完成把结果集输出到文件!! [root@test root]# psql -hlocalhost -Utest testWelcome to psq ...

  10. SGU 194 Reactor Cooling

    http://acm.sgu.ru/problem.php?contest=0&problem=194 题意:m条有向边,有上下界,求最大流. 思路:原图中有u-v low[i],high[i ...