How can I match the word before last one in string.
My current regex get the last one
I needto get the word before it "three"
>Solution :
You could use a positive lookahead here:
\w+(?=\s+\w+$)
Demo
This regex pattern says to match:
\w+ match a word
(?=\s+\w+$) which is followed by whitespace and the final word in the input
