Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我不知道如何解决以下问题:
preg_replace("/e[^t]/", "", "testet");
这将只删除“e”,但会删除“es”。我怎样才能做到它只删除第一个 e (并留下第二个'et')?
谢谢!
负前瞻:
preg_replace("/e(?!t)/", "", "testet")
正如这里所解释的,前瞻不会捕获字符(消耗字符),它们仅在匹配有效时才断言。
preg_replace("/e([^t])/", "$1", "testet");
而不是/e[^t]/尝试/e(?!t)/(负前瞻)
/e[^t]/
/e(?!t)/
让它不贪心
preg_replace("/e[^t]/u", "", "testet");