Copy link to clipboard
Copied
I've used GREP styles on and off, but I struggle to wrap my head around it and I can't find an answer that works for what I'm trying to accomplish...
The document I'm working with has a list of businesses setup like this:
Business Name (em space) Address (em) Phone Number (em) URL (em) Facebook URL (em) Instagram URL (paragraph break)
I use a nested style to make the Business Name bold ("up to 1 em space") and then I have a GREP style to make the URL bold. It works... but it will also bold characters in the Facebook and Insta URLs. I want the style to just apply to the URL and leave the Facebook and Insta alone.
This is my GREP style as it is:
[\l\u\d.]+(.com|.ca)
So anytime the letters "ca" or "com" show up in a Facebook or Insta URL it bolds them as well, plus any letters/digits preceding that.
With each business listing there is an ! in the text right before the Facebook URL—I use another GREP style to recognize the exclamation point and convert it to the typeface Social Shapes and give me a nice little Facebook icon. I've tried to figure out how to stop the GREP match when it encounters an exclamation mark, but this is beyond my skillset. I have no idea how else to make this work...
Can anyone help? TIA
I could not edit my reply, but here is the way to use the exclamation mark as end indicator. It sets an em space followed by a exclamation as a positive lookahead, so that the code only picks up urls followed by an em space and an exclamation.
[\l\u\d.]+(.com|.ca)(?= \!)
Copy link to clipboard
Copied
It worked for me on my sample when I added a positive look-behind with four digits together followed by an em space.
(?<=\d{4} )[\l\u\d.]+(.com|.ca)
This picked up only the URL directly following the phone number.
(if the phone numbers has a different format, or sometimes includes an extension, this code would need to change)
Copy link to clipboard
Copied
I could not edit my reply, but here is the way to use the exclamation mark as end indicator. It sets an em space followed by a exclamation as a positive lookahead, so that the code only picks up urls followed by an em space and an exclamation.
[\l\u\d.]+(.com|.ca)(?= \!)
Copy link to clipboard
Copied
Thank you, this worked the best and captured almost every single URL and left all the Facebook and Instagrams alone!
Copy link to clipboard
Copied
Doesn't my grep work for you?
From experience, the other grep does not find many URL.
Copy link to clipboard
Copied
How about
~m\K\S+\.c(a|om)(?=~m\!)