Skip to main content
Known Participant
September 16, 2018
Answered

Grep - find a character (or characters) within a word

  • September 16, 2018
  • 1 reply
  • 5220 views

I have two questions - both related to each other.

1. Supposing I want to find the r character in the selection of words below but ONLY the final r in each of the words. That is, the r must be followed by one of the patterns ai, as, a, ons, ez, ont.

travaillerai

travailleras

travaillera

travaillerons

travaillerez

travailleront

2. I want to find the xyz below as long as it's preceded by blah and followed by blahblah, as in this string:

blahxyzlahblah

Can anyone tell me the GREP expressions that would allow me to do both of these tasks?

Thanks in advance.

This topic has been closed for replies.
Correct answer Peter Kahrel

[\u\l]\Kxyz(?=[\u\l])

That is, xyz preceded and followed by a letter-- [\u\l] stands for upper- or lower-case letter.

1 reply

Peter Kahrel
Community Expert
Community Expert
September 16, 2018

1: r(?=(ai|as|a|ons|ez|ont)\b)

2: blah\Kxyz(?=lahblah)

Known Participant
September 16, 2018

That’s great. Thank you.

However, I should have been clearer with regard to my second question. I would like to find the xyz when it appears anywhere within a string, in other words it could have any number of random characters before it and any number of random characters after it, e.g.

joexyzbloggs

tarzanxyzofthejungle

What expression would allow for these circumstances?

Thank you in advance.

Peter Kahrel
Community Expert
Peter KahrelCommunity ExpertCorrect answer
Community Expert
September 16, 2018

[\u\l]\Kxyz(?=[\u\l])

That is, xyz preceded and followed by a letter-- [\u\l] stands for upper- or lower-case letter.