Home > Blockchain >  regex the word before last one in string
regex the word before last one in string

Time:02-03

How can I match the word before last one in string. My current regex get the last one

enter image description here

I needto get the word before it "three"

CodePudding user response:

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
  •  Tags:  
  • Related