I'm new in regex, first time I use them. Given a string, with multiple words, I need to extract the second word (word = any number of char between to spaces).
For example: "hi baby you're my love"
I need to extract "baby"
I think I could start from this: (\b\w*\b) that matches every single word, but I don't know how to make it skip the first match.
Thank's for suggestion guys, I've modified a little your regex and I finally find what I need:
(?<=\s)(.*?)(?=\s)
This one (?<=.)(\b\w+\b) was also kinda good but fails if I have string like "hi ba-by you're my love" splitting "ba-by" into "ba" and "by".
You can do it even without \b.
Use \w+\s+(\w+) and read the word from capturing group 1.
The regex above:
Note that \s+(\w+) is wrong, because the source string can begin with a space
and in such case this regex would have catched the first word.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With