Need GREP Stylesheet Help: Targeting one character for styling

Community Beginner ,
Dec 08, 2021 Dec 08, 2021

Copy link to clipboard

Copied

Hello,

 

I need to set the numbers after people's names in superscript. There is no space between the name and the number.

 

Ex:

"George1 lorem ipsum and George4 lorem ipsum went to the park."
*So the 1 and 4 would be set in superscript.

 

I have created a character stylesheet for the superscript.

Within the paragraph style I'm trying to set a GREP to select the numbers that come after the names to be styled.

 

I have the following:

 

(?=\w)\d(?=\s)

 

 

This works to some extent, but I have found issues where strings of numbers  are also being effected. For example, in "25 February 1796," the "5" in "25" is being targeted, but "1796" is not effected at all.

 

I tried changing the grep to the following, but that didn't seem to select anything.

 

(?=\u\l)\d(?=\s)

 

 

Any help appreciated.

TOPICS
How to , Scripting

Views

68

Likes

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

Adobe Community Professional , Dec 08, 2021 Dec 08, 2021

You're positive lookbehind in second example was off. Try this: 

 

(?<=\u|\l)\d(?=\s)

 

Likes

Translate

Translate
Adobe Community Professional ,
Dec 08, 2021 Dec 08, 2021

Copy link to clipboard

Copied

You're positive lookbehind in second example was off. Try this: 

 

(?<=\u|\l)\d(?=\s)

 

Likes

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 ,
Dec 08, 2021 Dec 08, 2021

Copy link to clipboard

Copied

Thank you very much!
So, the only difference was the "|" bar character between "\u" and "\l"?

What does the bar character signify?

 

Likes

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
Adobe Community Professional ,
Dec 08, 2021 Dec 08, 2021

Copy link to clipboard

Copied

You also were missing the < for the lookbehind. The | indicates either/or. Either a lowercase or uppercase letter precedes it. Some others better at GREP might have a better solution, but those were the two main differences. Your example was not a positive lookbehind. 

Likes

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
Adobe Community Professional ,
Dec 08, 2021 Dec 08, 2021

Copy link to clipboard

Copied

LATEST

Speaking of the | (bar), if you knew the names in advance and there weren't too many you could use

(?<=George|Mandy|Poe)

for the lookbehind. This would ensure you didn't accidentally match something like "Section A1".

- Mark

Likes

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
Adobe Community Professional ,
Dec 08, 2021 Dec 08, 2021

Copy link to clipboard

Copied

Edit: Brian's answer is better because it targets letters of names better than mine, which might get confused by punctuation, for example. I'll leave mine here for the record though. 🙂

 

Hi @KF Design, I'm no expert on regular expressions, but this worked for me in a basic test:

 

[^\d\s]+\K\d(?=\s)

 

It says find one or more characters that aren't digits or whitespace (then \K means ignore that after matching it), then find a *single* digit, followed by a whitespace.

- Mark

Likes

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 ,
Dec 08, 2021 Dec 08, 2021

Copy link to clipboard

Copied

Thank you very much for your reply!

Likes

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