Copy link to clipboard
Copied
I am currently trying to format some numbers in a table. I am doing this using GREP in a paragraph style that's applied to the numbers. My problem is that the numbers have so many special situations.
The goal is that the numbers I marked blue in the screenshot do not have to be formatted manually anymore.
The bold parts of the numbers are already being formatted with GREP.
Currently, this is the code I tried for formatting the blue numbers.. but it is not working.
(?<=-)(\d{2,3})(!\d)(!\.)
Arguably, my GREP skills are not that great.
Do you guys have any ideas what I coud try?
Copy link to clipboard
Copied
Your sample looks like "select any two digits that are preceeded by either a period or dash, and that are not followed by additional digits". Your regex seems to imply that you'd take any two or three digit number, right?
(?<=\.|-)(\d{2,3})(?!\d)
First: a positive lookbehind, "capture anything that follows a literal period or a dash".
Then: a group of "any two or three digits".
Followed by: a negative lookahead, "don't capture anything that doesn't precede a digit".
There weren't any three-digit valid groups to be captured in your sample, so I'm not sure why you need that, but I made some "-00XS to -999XS" examples to make sure this regex caught 'em.
Copy link to clipboard
Copied
Sorry, I had some copy-paste confusion over here, my previously posted negative lookahead is incorrect.
This matches your sample but it feels wrong, somehow:
(?<=\s|\.|-)(\d{2})(?=,|\>|\u)(?!\.)
It finds two-digit numbers preceded by whitespace, literal periods, or dashes, and followed by commas, uppercase letters, or end-of-paragraph locations, but not when follwed by periods. Even though your attempt at a regex included three-digit numbers, I've excluded them here because your sample doesn't include any three-digit numbers to capture.
Copy link to clipboard
Copied
Dear Joel,
thank you so much for your reply. Your description of the code really helped me understand it.
I tried the code, but unfortunately it is not highlighting every number, just the ones at the end. I am not sure why, all of the lookbehinds and lookaheads should be correct. I just added a whitespace to the lookbehind.
(?<=\s|\.|-)(\d{2})(?=,|\>|\u|\s)(?!\.)
Do you know what could be the reason for the code not catching all of the numbers?
 
Copy link to clipboard
Copied
Well, I don't think that the addition of the whitespace should change anything. Also, when I use your regex with your added whitespace, it still catches all the same groups as it did before. Similarly, when I try your regex on my install of InDesign, it doesn't look like your most recent posting at all. So you may want to check your expressions on your side.
Is there a reason that you're adding that space? You could also use the end-of-paragraph marker ($ without these parentheses), if you're trying to treat that pilcrow end-of-paragraph glyph as whitespace. It's just a location marker, it acts like a positive lookbehind. Similarly, you might want to think about using beginning-of-word (\< without parentheses) and end-of-word (\> without parentheses); it saves a lot of time trying to figure out all the possible permutations - you know, is it bound by a whitespace, a comma, a semicolon, a colon, an etc etc etc.
Lastly, I think that Mike has some really good advice, here. I often feel like trying to catch every possible permutation with ever-more-complex regular expressions is like trying to catch rain with a net. I mean, you can do it 🙂 but there might be an easier way.
Copy link to clipboard
Copied
I really don't know why the code is not working, I even tried it in a second, new document but it still does not catch all of the numbers it should catch. Can you show me a screenshot of your GREP window?
Here is what mine looks like, I hope none of the other GREPs are interfering with this one.. but even when I delete them, it still does not work.
Copy link to clipboard
Copied
Have you considered defining the paragraph style to bold everything, and aftewards use GREP styles to set relatively few expressions like "VAR" to a character style that forces it to Regular?
Copy link to clipboard
Copied
That is actually what I am doing right now.
This is how all of my GREPs for these product numbers look like:
(The AR numbers are also used sometimes, although not in the examples I posted here)
Copy link to clipboard
Copied
Copy link to clipboard
Copied
That is not how it should look like, you are correct. The "-" should be included in every case.
Copy link to clipboard
Copied
That is not how it should look like, you are correct. The "-" should be included in every case.
By @mira_00
And what is with the "*" and the "." ?
Always black and bold? Or not?
Copy link to clipboard
Copied
Unfortunately, I don't know what exactly your final goal is (see my last post). But I would go the direct route: Format only what needs to be formatted. Instead of formatting too much first and then formatting parts again.
That would be possible directly, for example:
 
Copy link to clipboard
Copied
In my opinion you only need
But it may well be that I am wrong.
Because I'm still not quite sure what the end result should look like. There is still some information missing from you.
Give it a try:
Above you can see the two grep styles (individually).
Below you see the combined result and your original image.
In the middle you see the two grep styles.
 
[ edited by pixxxelschubser ]
Oops. I overlooked a small detail. But now I'll wait for your answer.
Copy link to clipboard
Copied
Hi pixxxelschubser,
wow, thanks so much for your reply! I tried out the code and it worked 🙂
However, I did not get it to work with only two GREP styles, I had to add a third one.
Not sure why, but my texts did not look like the ones on your screenshot with only two GREPs. The blue numbers failed to format correctly. It looks like this, only two cases are recognized by the code:
So right now, I made an overarching paragraph style that formats everything to blue and bold, and three character styles: Regular, Bold and Bold with Color.
This way, it is working. But I think it's messier than your approach. What could be the reason it is not working the way you do it?
Here is the code and a screenshot of my text.
Regarding your question from above: It is okay for me for the "-" and "." to be included in the blue formatting everytime, as long as it is consistent.
The "*" can also be bold.
Find more inspiration, events, and resources on the new Adobe Community
Explore Now