Find substrings in string where substring encapsulated in specific character

前端 未结 1 420
既然无缘
既然无缘 2021-01-24 04:34

I have a string in the format:

\"The quick __grey__ fox jumps over the lazy __brown__ dog.\"

And I want to find and replace any words (or somet

1条回答
  •  不要未来只要你来
    2021-01-24 05:06

    To find some substring between two closest identical delimiters, use lazy dot matching:

    $pattern = '/__(.*?)__/';
    

    See demo

    To also match newlines, use /s modifier:

    $pattern = '/__(.*?)__/s';
    

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