Search code examples
phpregexstringsqlitecharacter

Regex show multiple choices but count as one


I need to find one of x or y in every line, something like: ^.(x|y){1}.$ it should find lines 3 and 4 only, but it shows 1 and 2 as well, what i don't want.

who said that x and y are important (2)
you have a y (2)
But here i have one x (1)
you have nothing (1)

Thanx for help

I tried to find the exact char count in every line. but some chars have multiple shapes


Solution

  • /^(([^y|x]*x[^y|x]*)|([^x|y]*y[^x|y]*))$/gm
    

    Explanation: match the string that starts with any amount of non-y and non-x characters followed by an x character that is followed by any non-y and non-x characters. Or match a string with the same rules for y.

    Working example here: https://regex101.com/r/D5VUlc/2