php preg_replace match string but replace only part of it

前端 未结 1 528
被撕碎了的回忆
被撕碎了的回忆 2021-01-23 08:14

I have this text: Retailer-ul Amazon foloseste metode severe pentru a-si descuraja etc. angajatii din depozite sa nu mai fure din produse. Pe ecrane li se arata siluete de

1条回答
  •  隐瞒了意图╮
    2021-01-23 08:53

    You need to wrap the [a-z] into a positive lookahead:

    \b[a-z]+\.\s(?=[a-z])
    

    See the regex demo

    The lookahead construct just checks if some pattern defined inside it appears to the right of the current location. So, (?=[a-z]) checks if there is a lowercase ASCII letter right after the whitespace matched with \s. If there is a lowercase, a match is returned (and the replacement occurs), if it does not find the small letter, the match is failed, no replacement occurs.

    0 讨论(0)
提交回复
热议问题