zoukankan      html  css  js  c++  java
  • [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

  • 相关阅读:
    SPOJ NDIV
    SPOJ ETF
    SPOJ DIVSUM
    头文件--持续更新
    SPOJ FRQPRIME
    SPOJ FUNPROB
    SPOJ HAMSTER1
    观光
    最短路计数
    拯救大兵瑞恩
  • 原文地址:https://www.cnblogs.com/Answer1215/p/5189838.html
Copyright © 2011-2022 走看看