Regex to match until including or not including : I'm looking for a Regex to find a substring starting at A, stopping at either B or C; however, when it's B, it shouldn't include the B, but when it's C, it should include the C. For example this text: `XXAXXXXBXX`, then it should return `AXXXX` but when it's `XXAXXXXCXX` it should return `AXXXXC`. I already looked at positive lookahead and stuff, but it doesn't work so far. Anyone an idea?