in reply to Re: Regex, match one or other character class
in thread Regex, match one or other character class

> [\.|\s]

> either a dot or a space

or a literal pipe symbol | ²

The OP seems to think he can have two alternative character classes inside [...]

To achieve this he needs (?:[CLASS1]|[CLASS2]) ... (the ?: is for not catching).°

Probably he just confused it with (\.|\s) or (?:\.|\s)

Cheers Rolf
(addicted to the 𐍀𐌴𐍂𐌻 Programming Language :)
Wikisyntax for the Monastery

edit

°) Sorry, in hindsight this doesn't make much sense (?:[CLASS1]|[CLASS2]) is the same like [CLASS1CLASS2] , 'or'-operations follow associative law

²) and the [\.] is redundant, it's the same like [.] and won't match everything

Replies are listed 'Best First'.
Re^3: Regex, match one or other character class
by hippo (Archbishop) on Apr 26, 2023 at 09:59 UTC
    and the [\.] is redundant, it's the same like [.] and won't match everything

    Yes, I am aware of that. However the OP's question was to explain why the regex he provided, in all its baroque splendour, did not match both the input lines. I think it would be distracting to go changing his regex and then explain how the modified form works rather than answer the question as posed. There are plenty of things I would change about the given regex to achieve the same end were I to write it of which this is merely one. Although the first thing would be to lose the /x which is causing far more confusion than it removes in this case IMHO.

    or a literal pipe symbol |

    That's a good observation and I'll amend my post to mention it. Thanks.


    🦛

      > Yes, I am aware of that.

      I know, this was directed at other readers and I wanted to cover all aspects, which ...

      > > The OP seems to think ...

      Cheers Rolf
      (addicted to the 𐍀𐌴𐍂𐌻 Programming Language :)
      Wikisyntax for the Monastery