Copy link to clipboard
Copied
Hello all,
I'm not so hot with GREP, but I love using it for formating text when I can.
I'd like to apply small caps to "st, nd, rd and th" when used in 1st, 2nd, 3rd, 4th, etc., but I'm having trouble limiting where it is applied. I've tried some positive look behind and look ahead rules, but I'm still failing.
I'm using the GREP below:
(?<=\d)th|nd|rd|st(?=.+?)
Using it for addressing like below:
151 West 34th Street
27th Fl.
Long Island City, NY 11101
I don't want the "st" in West or the "nd" in Island small affected, but haven't figured out how to control that. Any suggestions greatly appreciated.
Thanks,
Dennis
Hi @dennisy42803903, I'm no expert but I'm a huge fan of grep, too š
You could try this:
(?<=\d)(th|nd|rd|st)\b
I put parenthesis around the OR choices and added \b (word boundary).
- Mark
Copy link to clipboard
Copied
Hi @dennisy42803903, I'm no expert but I'm a huge fan of grep, too š
You could try this:
(?<=\d)(th|nd|rd|st)\b
I put parenthesis around the OR choices and added \b (word boundary).
- Mark
Copy link to clipboard
Copied
Hey Mark,
Thanks for the quick and effective reply. It definitely seems to work. I have to apply this to several hundred addresses, so hopefully I won't find any exceptions. However, first 30 examples look promising.
I really appreciate the help. I never thought to use a word boundary like that. I'll add that to my arsenal for next time.
Thank you!
-Dennis
Copy link to clipboard
Copied
Yeah the word boundary was to add a little more robustness against matching, say, a wacky start-up company name "12think". Adding the parenthesis to group options separated by bar (|) is almost always essential. In your original grep, I think the lookahead at the end would only apply to "st".