Regex for extracting first and last word from multi-word string

3.64K viewsProgramming
0

How can I write a regex that will return first and last word from multi-word string.
For eg:- “William Henry Gates” string should return “William Gates”

Changed status to publish
0

Here it is:- 
 /^\w+|\b\w+(?=$)/g

Answered question
Write your answer.

Categories