• 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โ€™eฬcran 2021-02-09 aฬ€ 17.14.54.png   

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

Capture dโ€™eฬcran 2021-02-09 aฬ€ 17.15.05.png

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

Capture dโ€™eฬcran 2021-02-09 aฬ€ 17.15.14.png

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

Capture dโ€™eฬcran 2021-02-09 aฬ€ 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โ€™eฬcran 2021-02-09 aฬ€ 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

1.8K

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โ€™eฬcran 2021-02-10 aฬ€ 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โ€™eฬcran 2021-02-10 aฬ€ 10.53.34.jpgCapture dโ€™eฬcran 2021-02-10 aฬ€ 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โ€™eฬcran 2021-02-10 aฬ€ 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