Skip to main content
Fred.L
Inspiring
February 8, 2022
Answered

[Grep] how catch a single quote/ apostrophe in Grep

  • February 8, 2022
  • 4 replies
  • 1232 views

Hi guys,

I used a grep style in order to capitalize the first letter of every word on a paragraph (for titles) and I wonder how to correctly catch the single quote/ apostrophe in the sentence, in order not to capitalize some words.

 

\b(?!(d.|de|des|du|et|au|aux)\b)[\u\l]

I used the following grep, which actually works fine but I had to cheat in order to make it work.

\b(?!(d.|de|des|du|et|au|aux)\b)[\u\l]

exemple of sentence to capitalize : " Messieurs, mesdames d'Arizona, bonjour "

 

As you could see, I used " d. " for not Capitalizing the " d' " and not making " D' ".

Since the folowwing grep doesn't work, what should I write to excatly catch the single quote/ apostrophe, rather than cheating using the dot.

\b(?!(d'|de|des|du|et|au|aux)\b)[\u\l] -- not working. the ' isn't recognized, neither \'

 

Thanks for your insights

  

This topic has been closed for replies.
Correct answer Peter Spier

Looks like ID is recognizing the apostrophe as a word boundary. Seems like putting it in a class does work, however.

Try

\b(?!(d[']|de|des|du|et|au|aux)\b)[\u\l]

Also, you may not need the de, des, or du if you use d[eu'] and au may cover aux as well, but I haven't tested that.

4 replies

Peter Spier
Community Expert
Community Expert
February 8, 2022

Been thinking about this a bit more, and while it might be working for you at the moment, I thinjk in the general case it may be a failure as it misght not capitalize some words you might intend to be capitalized if they happen to start with de, au or et.

Fred.L
Fred.LAuthor
Inspiring
February 8, 2022

I guess just adding a text space after au/de/... will do the thing 

jmlevy
Community Expert
Community Expert
February 8, 2022

This works:

 

 

\<\l(?!')

 

 

 but I have a question: why do you want to capitalize the first letter of each word of a title? It's against the French typographic rules and it seems that you work in French…

Fred.L
Fred.LAuthor
Inspiring
February 8, 2022

Thanks for the answer. Seems again there are many ways to get to a viable solution ^^
As per for my need Vs the French typographic rules, I know and understand the point, but let's just say the demand is for the game industry and typographic rules there are commonmy violated for the sake of a supposedly "visual improvement".

Besides, I have no real control on the decison 😕😕

Peter Spier
Community Expert
Community Expert
February 8, 2022

~' is the GREP sequence to find the apostrophe

Fred.L
Fred.LAuthor
Inspiring
February 8, 2022

Well, I tried that one too, but it doesn't work either 😕😕

Peter Spier
Community Expert
Peter SpierCommunity ExpertCorrect answer
Community Expert
February 8, 2022

Looks like ID is recognizing the apostrophe as a word boundary. Seems like putting it in a class does work, however.

Try

\b(?!(d[']|de|des|du|et|au|aux)\b)[\u\l]

Also, you may not need the de, des, or du if you use d[eu'] and au may cover aux as well, but I haven't tested that.

Fred.L
Fred.LAuthor
Inspiring
February 8, 2022

Sorry for the double writting of the grep. A shame we can't edit our posts…