user1874594
user1874594

Reputation: 2493

regex notepad++ select a word immediately following ( & preceding ) selection

I need to select just the word that follows a specific selection ( and one that precedes it - both are separate regexes - not to be combine em )

the pattern is 
<variable verbiage>
 <one or more spaces or a newline>
"on"
<one or more spaces or a  newline>
 Word_to_select
<optional variable verbiage>
Examples 
1 ) she looks too pretty I never meant Hillary ya da ya ON delta.airlines next word 
2 )yada ya        
Daddy Daddy
     on
united.airlines  hullah
gulla ; 
 3)yada ya         Daddy Daddy  on
American.airlines some 
ricotta cheese 

I need to get in all cases
'Following' regex :

delta.airlines
united.airlines 
american.airlines 

'Preceding' regex :

ya
Daddy
Daddy


What I tried

(\S)\s* on \s*(\S+)

the selection includes "on" and goes back further .

Upvotes: 0

Views: 65

Answers (2)

Leonardo Neninger
Leonardo Neninger

Reputation: 586

Look this demo. you can select group 1 to get "preceding" and 2 to select "following".http://regexr.com/3g7ps

Upvotes: 2

Wiktor Stribiżew
Wiktor Stribiżew

Reputation: 627292

You may use

\bon\s+\K\S+

See the regex demo.

Match case option should be deselected or just prepend the pattern with (?i).

Details:

  • \bon - a whole word on
  • \s+ - 1 or more whitespaces
  • \K - match reset operator
  • \S+ - 1+ non-whitespace symbols.

enter image description here

Upvotes: 1

Related Questions