How to use Regex to find a string with only spaces delimiting it? -



i'm trying parse string whitespace delimited.

i using /\b[somestring]\b/

but don't want pick words have any punctuation next it.

so if parsed string:

"trying to,\n test out,\n trying has taken while.\n trying stuff fun,\n stuck" 

with /\btrying to\b/

i find three, want 2 because don't want include

"trying to," 

--edit

expected output

trying trying 

if understood correctly question, can use regex lookahead this:

trying to(?=\s) 

working demo

the idea search string trying to following space character

edit: if want include having \n, can use:

trying to(?=\s|\\n) 

btw, if want include literal space , literal \n, don't need use regex lookahead, simple group this:

trying to(?:\s|\\n) 

Comments

Popular posts from this blog

How to understand 2 main() functions after using uftrace to profile the C++ program? -

c# - Update a combobox from a presenter (MVP) -

How to put a lock and transaction on table using spring 4 or above using jdbcTemplate and annotations like @Transactional? -