How to get a word which is present in a sentence after 3 spaces using regular expression?

Ganeshm1
Tera Guru

Hi All,

 

I want to get the the word which is present after the 3 spaces in a sentence using regular expression.

 

EX:

I love to work in ServiceNow. 

I want to get the word 'WORK' using regular expression. Kindly provide your inputs on this. Thank You!

 

Regards,
Ganesh

1 ACCEPTED SOLUTION

AndersBGS
Tera Patron
Tera Patron

Hi @Ganeshm1 ,

 

Here you go: 

/^(?:\S+\s+){3}(\S+)/gm
This refer to if you take the this text string as example: "This is an example sentence for testing.", then you would get "example".
 

If my answer has helped with your question, please mark my answer as accepted solution and give a thumb up.

 

Best regards

Anders 

If my answer has helped with your question, please mark my answer as the accepted solution and give a thumbs up.

Best regards
Anders

Rising star 2024
MVP 2025
linkedIn: https://www.linkedin.com/in/andersskovbjerg/

View solution in original post

2 REPLIES 2

AndersBGS
Tera Patron
Tera Patron

Hi @Ganeshm1 ,

 

Here you go: 

/^(?:\S+\s+){3}(\S+)/gm
This refer to if you take the this text string as example: "This is an example sentence for testing.", then you would get "example".
 

If my answer has helped with your question, please mark my answer as accepted solution and give a thumb up.

 

Best regards

Anders 

If my answer has helped with your question, please mark my answer as the accepted solution and give a thumbs up.

Best regards
Anders

Rising star 2024
MVP 2025
linkedIn: https://www.linkedin.com/in/andersskovbjerg/

Ganeshm1
Tera Guru

Thank you so much for your reply @AndersBGS