重要编辑:由于许多人说应该避免这种情况并且几乎无法使用RegEx,我将允许您提供其他一些解决方案.从现在开始,任何解决方案都可以用作答案,最后是解决方案.谢谢!
让我们说:
$line = "{ It is { raining { and streets are wet } | snowing { and streets are { slippy | white }}}. Tomorrow will be nice { weather | walk }. }"
Run Code Online (Sandbox Code Playgroud)
期望的输出:
It is raining and streets are wet. Tomorrow will be nice weather.
It is raining and streets are wet. Tomorrow will be nice walk.
It is snowing and streets are slippy. Tomorrow will be nice weather.
It is snowing and streets are …Run Code Online (Sandbox Code Playgroud)