• Global community
    • Language:
      • Deutsch
      • English
      • EspaƱol
      • FranƧais
      • PortuguĆŖs
  • ę—„ęœ¬čŖžć‚³ćƒŸćƒ„ćƒ‹ćƒ†ć‚£
    Dedicated community for Japanese speakers
  • ķ•œźµ­ ģ»¤ė®¤ė‹ˆķ‹°
    Dedicated community for Korean speakers
Exit
9

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

Engaged ,
Dec 15, 2023 Dec 15, 2023

Copy link to clipboard

Copied

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

TOPICS
How to , Scripting

Views

258

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Community Expert , Dec 16, 2023 Dec 16, 2023

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

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

Votes

Translate

Translate
Community Expert ,
Dec 15, 2023 Dec 15, 2023

Copy link to clipboard

Copied

Hi @palala fog, here's my attempt:

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

- Mark

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
Dec 15, 2023 Dec 15, 2023

Copy link to clipboard

Copied

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

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
Dec 15, 2023 Dec 15, 2023

Copy link to clipboard

Copied

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

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guide ,
Dec 16, 2023 Dec 16, 2023

Copy link to clipboard

Copied

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

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Engaged ,
Dec 16, 2023 Dec 16, 2023

Copy link to clipboard

Copied

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:

Screenshot 2023-12-16 at 10.16.27 AM.png

ā€ƒ



Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
Dec 16, 2023 Dec 16, 2023

Copy link to clipboard

Copied

I don't understand what problem your are trying to solve, nor what the issue with my regex was.

 

Exactly which characters did you expect to be highlighted in your screenshot?

Is the problem that it includes punctuation (the comma)? Try something like this:

\w\s+\K\w*\K\w

Should it only have highlighted the  "t" at the end of "aut" and nothing else? Try:

\w\s+\K\w*\K\w(?=.*)

 

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Dec 16, 2023 Dec 16, 2023

Copy link to clipboard

Copied

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

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

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Engaged ,
Dec 16, 2023 Dec 16, 2023

Copy link to clipboard

Copied

LATEST

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.

Screenshot 2023-12-16 at 8.49.48 PM.png

***********

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

fringe.png

ā€ƒ**************

 

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.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines