Home > Mobile >  Regex select second and third word in a string
Regex select second and third word in a string

Time:10-13

I've got a string where I need to aleays select just the second and third wodr in a string. Currently I can only select the first three words but I need to skip the first word. I currently have:

^(?:[^ ]*\ ){2}([^ ]*)

Any help wouild be aprreciated. Thanks!

CodePudding user response:

You can capture the second and the third "word" as in 1 or more non whitespace characters:

^\S  (\S  \S )

Regex demo

Or if supported with a lookbehind:

(?<=^\S  )\S  \S 

Regex demo

CodePudding user response:

I think this is the regex you're looking for:

(?<=\s)([^ ]*)

Link to example: https://regex101.com/r/wSdzLe/1

  • Related