Search code examples
regexregex-group

Transform regular expression without using pipe


What I'm trying to achieve is a regex expression that can find both "" and a string starting with abc_.
However I cannot use | or ^ due to code restrictions.

Do you think there is any chance to transform this regex, by removing the pipe ""|abc_.* and getting the same result?

https://regex101.com/r/HBvG3K/2


Solution

  • (abc_.*)?("")?
    

    Remember that we are using optional regex character(?). Depending on the input type it may also match a string which contains "". As I understand based on your examples, a given string will contain either "" or abc_.* or some other strings.Hence this is fine.

    Demo and explanation:

    https://regex101.com/r/HBvG3K/3