• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

GREP: Finding a specific word within email and web addresses

Community Beginner ,
Jun 07, 2019 Jun 07, 2019

Copy link to clipboard

Copied

Hi

When it comes to GREP I'm a bit of a novice but have managed to put some nifty bits together in paragraph styles and GREP searches to make my life much easier. However, I've just come across an error I hadn't accounted for.

The original plan was to automatically apply a character style to a specific part of an email/web address. For example, my main domain is www.mango.com and I need to bold the 'ang' part. I have a few other domains to consider; www.mymango.com and www.mangofruit.com. I had been using;

(?<=\.m).*?(?=g.)|(?<=\@m).*?(?=g.)

I know email addresses with mymango.com would not be covered because of the \@m, but they're not used. The recent problem I've discovered is some names are captured in email addresses, such as;

bob.mint@mango.com

All email addresses are set as firstname.surname@domain. Is there a way of tweaking my GREP to cover only the part I need to bold and nothing else?

Views

488

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 ,
Jun 07, 2019 Jun 07, 2019

Copy link to clipboard

Copied

Hi!

Not sure I understood perfectly your request, but I think your regex can't do www.mymango.com.

It will start catching after the first found "m", just like in your email address.

Maybe you just want to catch "ang" while preceeded by a "m" and followed by a "o" then maybe some characters, then ".com"?

Give this one a try:

m\Kang(?=o.*\.com)

Please report back if it doesn't achieve what you want.

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 Beginner ,
Jun 07, 2019 Jun 07, 2019

Copy link to clipboard

Copied

Wow, quick and simple! I thought that might be the case. It works although I remembered there are other regional domains to account for (eg .de, .fr, etc) so removed the com. That looks like it catches everything. Thanks!

Never knew about \K so that's an interesting addition. Currently trying to get my head round how I'd made it so complicated!

m\Kang(?=o.*\.)

ps. I noticed I had quoted my code incorrectly and it should have originally been an o where I'd put g.

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 ,
Jun 07, 2019 Jun 07, 2019

Copy link to clipboard

Copied

Yeak \K is Kool...

In your specific case, it does nothing more than a "classical" positive lookbehind, (just shorter to write ^^) but its real power lies in the fact that it can deal with quantifiers (+ * ? etc.)

About your latest regex m\Kang(?=o.*\.) please note that it will catch (m)ang(o) even in classical sentences which ends with a dot.

Even plurals.

Maybe it's fine for you, but be aware of it...

By the way, you don't even need the .*\. part then ^^ m\Kang(?=o) would do (almost) the same job.

mango.gif

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 Beginner ,
Jun 07, 2019 Jun 07, 2019

Copy link to clipboard

Copied

LATEST

Thanks again. Yes, I'm aware that it'll catch all mangoes but thankfully that was only an example and my real-world case will not create issues like that

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