[Regular Expressions] Find a String that Precedes Another String ?= , ?!
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 ?= , ?!的更多相关文章
- PCRE Perl Compatible Regular Expressions Learning
catalog . PCRE Introduction . pcre2api . pcre2jit . PCRE Programing 1. PCRE Introduction The PCRE li ...
- 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 --正则表达式官方教程
http://docs.oracle.com/javase/tutorial/essential/regex/index.html This lesson explains how to use th ...
- 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 ...
- 正则表达式(Regular expressions)使用笔记
Regular expressions are a powerful language for matching text patterns. This page gives a basic intr ...
- 自学Zabbix8.1 Regular expressions 正则表达式
点击返回:自学Zabbix之路 点击返回:自学Zabbix4.0之路 点击返回:自学zabbix集锦 自学Zabbix8.1 Regular expressions 正则表达式 1. 配置 点击Adm ...
随机推荐
- 可失败构造器(Failable Initializers)
Xcode6.1中Swift的最新版本是1.1,在该版本中引入了一个新的特性:可失败构造器.通过构造器初始化实际上是给class或struct的每一个存储属性(参数)提供初始值,进行对象实例化的过程. ...
- SELECT--UNION,UNION ALL,MINUS, INTERSECT,EXISTS
SELECT--UNION,UNION ALL,MINUS, INTERSECT返回两个查询结果的集合操作,两个查询结果集必须字段相同.UNION和UNION ALL并集操作,UNION并集后去掉重复 ...
- Android之Activity启动的源码简介
从一个简单的startActivity开始 进入了Activity.java public void startActivity(Intent intent) { this.startActivity ...
- 使用.NET框架、Web service实现Android的文件上传(一)
上面是上传结果的展示,下面具体讲一下实现过程. 一.Web Service (.NET) namespace VedioPlayerWebService.service.vedios { [WebSe ...
- SQL Server2008知识点总结
1.SQL Server2008基本服务及功能 2.管理SQL Server2008安全:登录.权限.数据库用户.管理角色.服务器角色.管理数据库角色. 3.数据库管理.表管理(临时表和系统表.列值属 ...
- iOS_SN_Socket网络编程(一)
1.Socket简介 首先让我们通过一张图知道socket在哪里? socket在哪里 Socket是应用层与TCP/IP协议族通信的中间软件抽象层,它是一组接口. 2.TCP和UDP的区别 在这里就 ...
- NPOI导入导出Excel (2)
简单演示一下创建一个Workbook对象,添加一个工作表,在工作表中添加一行一列: using System;using System.Collections.Generic;using System ...
- 分布式Session共享(二):tomcat+memcached实现session共享
一.前言 本文主要测试memcached实现session共享的实现方式,不讨论如何让nginx参与实现负载均衡等. 二.环境配置 本测试在Window下进行 name version port To ...
- C#在使用串口读一长段数据时,前面加延时,等串口缓冲全部收到再去读
Thread.Sleep(3);//延时一会,等接受完成再去读
- smarty 常用参数
section的产生是为解决foreach的不足的,与foreach一样,它用于设计模板内的循环块,它较为复杂,可极大程序上满足程序需要,所以在程序中我习惯使用它而不使用foreach,基本原形为:{ ...