Skip to main content
Inspiring
December 15, 2023
Answered

How to grep the last letter in a consecutive second word?

  • December 15, 2023
  • 3 replies
  • 773 views

It’s possible to find the last letter?


S E A R C H:
my ?????e

my= is a the first word in the search (may be ours, yours, any word)

?????e = is the second word where grep must detect the last letter, e.


R E S U L T S:

my eye

my fate
my shame

my aerogramme

Thanks
ps. Have a very precarious grep that only catches the condition in a word: (o)h?\b

This topic has been closed for replies.
Correct answer m1b

Hi @palala fog, so you want a separate grep that will select two words my * ?

(\bmy)\s([[:alpha:]]+\b)

3 replies

Inspiring
December 16, 2023

hi m1b,

grep is working as it recognizes words ending in a specific letter.

Is it possible (since I didn't mention it) that the result shows the two words involved?
Tried to do it but the expression is a unity.

the idea is to catch both to make lists.
O U T P U T
my eye
my rate

thanks.

Mayhem SWE:
thanks. your grep is almost fine but doing this:



m1b
Community Expert
m1bCommunity ExpertCorrect answer
Community Expert
December 16, 2023

Hi @palala fog, so you want a separate grep that will select two words my * ?

(\bmy)\s([[:alpha:]]+\b)
Inspiring
December 17, 2023

Yes, m1b. Thanks. It is perfect. Thanks also for your time.
 With Indexmatic (thanks M. Autret) it will be perfect and easy to accomplish the required lists.

***********

Dear Fringe: is our fault. We couldn't put in motion your formulae:



 **************

 

Hi Mayhem SWE,
Let me clarify  the purpose of this grep, not clearly specified.
We need to catch groups of words that belong to a gendered idiomatic language: masculine, feminine and neuter. Concordance and genre should explain the grep's nature. Don't match and mistakes are detected.
Thanks for you ideas that helped the whole thread.

FRIdNGE
December 16, 2023

if just paras with always 2 words:

 

.$

 

If paras with any length of words (1, 2, 3 or more):

 

(?:^\S+\s\S*)\K\S

 

(^/)  The Jedi

m1b
Community Expert
Community Expert
December 15, 2023

Hi @palala fog, here's my attempt:

\bmy\s\b[^\h\n\r]+\K[[:alpha:]]\b

- Mark

Mayhem SWE
Inspiring
December 15, 2023

Interesting! Regex engines normally won't do variable length lookbehind., but I did not know about \K before.

 

Not knowing anything more about the OP's requirements this seems simple and work good enough:

 

\S +\K\S*\K\S
Mayhem SWE
Inspiring
December 15, 2023

Something was broken with my copy paste, should've been a \s+ where a space snuck in and posts cannot be edited?!

\S\s+\K\S*\K\S