I encounter different scenarios where strings are involved. The goal is to extract the text in between the ||
symbols. If there is only one ||
, then the first part should be taken.
For example:
Useless information|| basic information|| advanced information|| super information|| no information
Expected outcome: basic information, advanced information, and super information
Useless information|| basic information|| advanced information|| no information
Expected outcome: basic information and advanced information
Useless information|| basic information|| no information
Expected outcome: basic information
Useless information|| no information
Expected outcome: Usless information
I have experimented with the following regex patterns:
||[^||]*||[^||]*
and also tried:
([^||]*)(?=||)
However, these patterns do not consistently yield the expected results in all scenarios. Is it possible to achieve this extraction using a single regex expression?