• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

[GREP] lookbehind vs \K

Enthusiast ,
Feb 09, 2021 Feb 09, 2021

Copy link to clipboard

Copied

Bonsoir à tous,

Je suis en Indesign 2021, sur mac OS «BIG SUR»

j'utilé le commande Lookbehind « (?<=\d+\.) » ceci ne marche plus comme mais comme ça (?<=\d\.) ... Après quelque recheche, il est recommndé de passer à la commende \K, cette comme de à des problèmes!!!

 

exemple voir images par étape.

la base de la recheche.

Capture d’écran 2021-02-09 à 17.14.54.png   

Premièr passage : il en trouve 83 (pas le 1. et ni le 3.)

Capture d’écran 2021-02-09 à 17.15.05.png

Deuxième passage : il en trouve 21 (toujours pas le 1.)

Capture d’écran 2021-02-09 à 17.15.14.png

Troisième passage :  il en trouve 0 !!!??? (toujous pas le 1. et d'autre )

Capture d’écran 2021-02-09 à 17.21.46.png

 

Quatrième passage en suppriment le format de recheche : enfin il trouve le premier paragraphe «1.» et 151 autres

Capture d’écran 2021-02-09 à 17.24.18.png

 

Voilà, quelqu'un peux m'expliqué ce qui ne fonctionne pas, ou se que je fais de mal dans la commande?

Ou cette commande (\K) est si peut fiable ? 

 

Merci à vous

 

Philou (bien enbété)

PS. je ne traduit pas avec Google, sous le poste clic sur tranlation merci à vous

TOPICS
Bug , Performance , Scripting

Views

2.4K

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

Community Expert , Feb 09, 2021 Feb 09, 2021

Tu ne peux pas utiliser de quantificateurs dans les lookbehind. Donc pas de +, ni de * ou ?

C’est sûrement pour cela qu’on ta recommander d’utiliser \K

Il semble y avoir un bogue (j’ai vu ça fréquemment) avec la combinaison de ^ et de \K
Tu peux contourner cela avec (?s)^\d+\.\K\h

Votes

Translate

Translate
Community Expert ,
Feb 09, 2021 Feb 09, 2021

Copy link to clipboard

Copied

J'ai un peu de mal à comprendre ce que tu recherches : dans le titre du message, tu parles de « Lookbehind »? Tu écris aussi que tu utilises la commande « (?<=\d+\.) », mais dans les captures d'écran, ta recherche est complètement différente : (^\d+\.)…

Si tu recherches à remplacer un ou plusieurs chiffre(s) suivi(s) d'un point, ^\d+\. fonctionne très bien. Ou alors tu recherches les espaces qui sont précédées d'un ou plusieurs chiffre(s) suivi(s) d'un point ? dans ce cas, cette commande fonctionne : 

(?<=\d\.)\s

Votes

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
Enthusiast ,
Feb 09, 2021 Feb 09, 2021

Copy link to clipboard

Copied

Bonjour jmlevy,

Comme indiqué dans la question cette commande ne fonction plus ou pas ( malgré des année d'utilisation).

Il ne trouve rien ...Il ne trouve rien ...

effetivement le grep suivant fonction mais je ne teste pas avec le "^" dans le groupe

Capture d’écran 2021-02-10 à 08.15.39.png

 

Votes

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
Enthusiast ,
Feb 09, 2021 Feb 09, 2021

Copy link to clipboard

Copied

(?<=\d\.)\s, sa recheche les chiffres de 0 à 9 n'import où, je recherche un nombre (pas un chiffre) en début de ligne  (pas ailleurs), merci pour ta contribution.

Votes

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 Expert ,
Feb 10, 2021 Feb 10, 2021

Copy link to clipboard

Copied

Je reviens sur ma question d'hier : que souhaites-tu trouver ? S'il s'agit de remplacer les espaces qui suivent un point précédé d'un chiffre par ->, je réussis à le faire de 2 façons :

Capture d’écran 2021-02-10 à 10.53.34.jpgCapture d’écran 2021-02-10 à 10.56.51.jpg

Mais peut-être que je ne comprends pas la question…

Votes

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
Enthusiast ,
Feb 10, 2021 Feb 10, 2021

Copy link to clipboard

Copied

Merci Jmlevy, c'est trouvé un nombre de 1 à 999 voir plus (ex.) en debut de paragraphe suivit par un point et un blanc, pour le remplacer par un demi-cadratin (~>), il ne doit pas trouvé autre chose ex :

«... sfsfs sshsh jshsjh serction 4. Autre chose ... ». merci à toi regarde les commantaire de Peter et de Jean-Claude.

Votes

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 Expert ,
Feb 10, 2021 Feb 10, 2021

Copy link to clipboard

Copied

As-tu essayé ceci ? Ça fonctionne parfaitement.

Capture d’écran 2021-02-10 à 17.21.21.jpg

Votes

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 Expert ,
Feb 09, 2021 Feb 09, 2021

Copy link to clipboard

Copied

Tu ne peux pas utiliser de quantificateurs dans les lookbehind. Donc pas de +, ni de * ou ?

C’est sûrement pour cela qu’on ta recommander d’utiliser \K

Il semble y avoir un bogue (j’ai vu ça fréquemment) avec la combinaison de ^ et de \K
Tu peux contourner cela avec (?s)^\d+\.\K\h

Votes

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
Enthusiast ,
Feb 09, 2021 Feb 09, 2021

Copy link to clipboard

Copied

Bonjour Jean-Claude, le non fonctionnement avec +,* et ?, c'est nouveau ???, j'ai des pages de commande avec un multi-find change maison !!!

ex:

grep	{findWhat:"(?<=[\\d+])\\p{Zs}(et|à)\\p{Zs}(\\d+|[sS]\\.)"}	{changeTo:" $1~S$2"}	{includeFootnotes:true, includeMasterPages:true, includeHiddenLayers:true, wholeWord:false}	// philou modifié du 17 janvier 2011

cette commande fonctionne : "(?<=[\d+]\.)\s"

là, c'est OKlà, c'est OK

Votes

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 Expert ,
Feb 10, 2021 Feb 10, 2021

Copy link to clipboard

Copied

Le non-fonctionnement avec +,* et ?, ce n’est pas nouveau. C’est une limitation que l’on retrouve dans le Regex.

Ton (?<=[\d+]\.)\s fonctionne, seulement à cause que tu n’as pas spécifié de début de paragraphe (?<=^[\d+]\.)\s et que tu as mis le \d dans un jeu de caractères. En fait tu recherches un chiffre ou le signe plus. Les +,* et ? entre [] ne sont plus des quantificateurs, mais le caractère littéraux dans ce cas.

Votes

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
Enthusiast ,
Feb 10, 2021 Feb 10, 2021

Copy link to clipboard

Copied

EXACTE !!! un chiffre (0-9) ou le "+" ..., tres bonne lecture Jean-Claude !! je viens de teste  😉

Effectivement, pour ta ligne avec le \K ((?s)^\d+\.\K\h) ton GREP fait le travail!! mais si je change le "^" au debut comme ceci "^(?s)\d+\.\K\h", il bug ... OK on avence c'est super !!

Votes

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 Expert ,
Feb 09, 2021 Feb 09, 2021

Copy link to clipboard

Copied

If I understand you right - try to use

\r\d+\.\K\h

and then manually change the very first occurrence.

 

It could be the same behaviour like here:

indesign.uservoice.com/forums/601180-adobe-indesign-bugs/suggestions/41635084-grep-position-marker-b...

 

----------------

But only one question:

Why don't you use auto-numbering in paragraph format?

 

Votes

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
Enthusiast ,
Feb 09, 2021 Feb 09, 2021

Copy link to clipboard

Copied

Bonjour Pixxxelschubser, merci pour ta contribution.

Votes

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
Enthusiast ,
Feb 09, 2021 Feb 09, 2021

Copy link to clipboard

Copied

cet commande est apparu il y a quelque année (4 ou 5 ans) si mes souveneir son bon,  ce que je ne comprand pas, c'est le manque de présition de la comme \K, relance plusieur fois, pour qu'il trouve pour qu'il entrouve à chaque fois, et être bloqué par une option de style de parragraphe, c'est pas normal !! et c'est pour ca que je ne l'utilise pas, se côté allétoire n'est pas possible en production de livres.

(voir fichier joint desolé il ne veux pas prandre mon idml, donc CC2021 voici un lien pour idml https://www.dropbox.com/s/okwmys6qs00ddgf/testedebase.idml?dl=0).

ou je l'utilise mal !!

 

   

Votes

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 Expert ,
Feb 10, 2021 Feb 10, 2021

Copy link to clipboard

Copied

le non fonctionnement avec +,* et ?, c'est nouveau ???

 

No, it's not new. It's standard behaviour in all regular-expression dialects, and was described in detail by Friedl (Mastering Regular Expressions)

 

cette commande fonctionne : "(?<=[\d+]\.)\s"

 

It does indeed. Which is bizarre and unexpected (for me, anyway). (?<=[\d+]\.)\s works, (?<=\d+\.)\s does not. Looks like a bug, but one that improves the behaviour. Tant mieux!

 

P.

Votes

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 Expert ,
Feb 10, 2021 Feb 10, 2021

Copy link to clipboard

Copied

Peter, (?<=[\d+]\.)\s does not work really. Only works because there is no ^ specified and because the use of []. In fact, this regex search for [one digit or a plus sign] not one or more digits.

Votes

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 Expert ,
Feb 10, 2021 Feb 10, 2021

Copy link to clipboard

Copied

Thank you for pointing out my forgetting about the ^ marker, Jean-Claude. 

But you're wrong that "this regex searches for [one digit or a plus sign] not one or more digits". This one:

(?<=^[\d+]\.)\s

matches single-digit numbers at the start of a line. So it doesn't work as expected (unless you have no double-digit numbers, hehe).

@Liphou -- To create a classic variable-width lookbehind, you have to enumerate the variants:

((?<=^\d\.)|(?<=^\d\d\.))\s

\K is much simpler, naturally.

P.

Votes

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 Expert ,
Feb 10, 2021 Feb 10, 2021

Copy link to clipboard

Copied

When I said: "this regex searches for [one digit or a plus sign] not one or more digits".

I was just describing [\d+] instead of \d+ and if you had the ^ it will indeed only works for single digit because of that.

 

Votes

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 Expert ,
Feb 10, 2021 Feb 10, 2021

Copy link to clipboard

Copied

Oh, madre de dios! Of course. It should be [\d]+

New glasses. More coffee.

Votes

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
Enthusiast ,
Feb 10, 2021 Feb 10, 2021

Copy link to clipboard

Copied

Hi Peter,

 

Merci pour ton intervantion qui ma ouvert les yeux sur la limite du "lookbehind". on avence super.

Votes

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 Expert ,
Feb 10, 2021 Feb 10, 2021

Copy link to clipboard

Copied

Have said all this...

^\d+\.\K\s should be working without the need to add (?s) in front of it. This is working in others app like BBEdit.

Votes

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
Enthusiast ,
Feb 10, 2021 Feb 10, 2021

Copy link to clipboard

Copied

Donc pour conclure :

 

(?<=\d+)\p{Zs}((?=ans?)|(?=jours?))\b" --> KO

 

(?<=\d)\p{Zs}((?=ans?)|(?=jours?))\b -> OK
\d+\K\p{Zs}((?=ans?)|(?=jours?))\b -> OK

MAIS  PAS :

^\d+\K\p{Zs}((?=ans?)|(?=jours?))\b -> BUG

plutot ça ...

(?s)^\d+\K\p{Zs}((?=ans?)|(?=jours?))\b

 

J'ai du travail qui matent avec ça !!

 

 

 

Votes

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 Expert ,
Feb 10, 2021 Feb 10, 2021

Copy link to clipboard

Copied

You can have variable-length items in lookaheads, so instead of 

((?=ans?)|(?=jours?))

you can use 

(?=(an|jour)s?)

 

Votes

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 Expert ,
Feb 10, 2021 Feb 10, 2021

Copy link to clipboard

Copied

@Liphou  Like Peter said, variable-length is possible in lookahead (not in lookbehind).

Votes

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 Expert ,
Feb 10, 2021 Feb 10, 2021

Copy link to clipboard

Copied

@Liphou 

Peter will not suggest it... But I will 🙂
Must read his eBook: 
https://creativepro.com/product/grep-in-indesign/

and in French that one from Laurent Tournier.
https://www.indigrep.com

Votes

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