Skip to main content
Mugen777
Inspiring
December 2, 2018
Answered

My brain about to explode... Need help about GREP

  • December 2, 2018
  • 6 replies
  • 1545 views

Hey everyone

I have several abbreviations like v.t. v.p. v.pr. ... etc.

Here is the problem, i am trying to find words that come after abbreviations until first ":" .

I mean -->   asdasdasd v.t. asdddddddasda: asdasdasdasdasd

I tried to use positive lookback --> (?<=v\.t\.|v\.i\.|v\.p\.).+?: and it works.

If i search v.pr., v.imp. only, it works as well. But when i try to search both v.i. and v.pr. ...etc. it stops working. (Can't find a match)

(?<=v\.pr\.|v\.imp\.).+?: --> This doesn't work as well.

Funny thing is, when i try to use positive lookahead it works again...  ( (?=v\.t\.|v\.i\.|v\.pr\.).+?: -->This works...)

I really can't understand 😕😕

(I have abbreviations like "n.m.pl." as well, and i didn't even try them yet...)

(Should i create a GREP style one by one? Is there an easier way?)

    This topic has been closed for replies.
    Correct answer pixxxelschubser

    Hi Chad

    yes.

    But unfortunately your grep is much too greedy.

    Will find false positive hits:

    end of sentence with following letters and ":" or

    mr. with following letters and ":" or

    Dr. med. with following letters and ":" or …

    My own favorite with a bit more security could be:

    [nvp]\.(\l{1,3}\.){0,2}\K[^:]+:

    With this grep false positive hits are possible but unlikely.

    6 replies

    Mugen777
    Mugen777Author
    Inspiring
    December 2, 2018

    @Chad Chelius

    pixxxel schubser

    Thank you again, that post become a great source for later use as well. Thank you for the detailed explanation as well.

    Have a great day : )

    Mugen777
    Mugen777Author
    Inspiring
    December 2, 2018

    pixxxel schubser

    @Chad Chelius  (I couldn't tag you : )

    Thank you for answers

    Both of them working but since the second one is less complicated and more people can use it later, i choose it as the correct answer.

    (really tho, how couldn't i thought that... : ) Looks like experience talks : )

    >Weird thing is, when i search with GREP it looks like

    v.t. test: text text text.

    v.i. test: text text text.  (it includes the dot in the first line as well)

    But when i use it in paragraph style, it works perfectly.

    Is it normal?

    pixxxelschubser
    Community Expert
    Community Expert
    December 2, 2018

    That's the "problem" with Chad Chelius​ grep: false positive hits.

    Read my post #8 again please.

    hammer0909
    Community Expert
    Community Expert
    December 2, 2018

    I think the OP is indicating that his text is pretty simple and both expressions work. Pixel schubser you're right though in that I wrote that expression in a very basic way. You're example is much more robust and definitely accounts for more variables than mine. So that everyone can benefit from your example, I created an image below that explains exactly what your expression is doing for the benefit of other people learning GREP. If you find that I made a mistake, please correct me.

    hammer0909
    Community Expert
    Community Expert
    December 2, 2018

    This seems to be working for me

    (?<=\.\s).+\:

    pixxxelschubser
    Community Expert
    pixxxelschubserCommunity ExpertCorrect answer
    Community Expert
    December 2, 2018

    Hi Chad

    yes.

    But unfortunately your grep is much too greedy.

    Will find false positive hits:

    end of sentence with following letters and ":" or

    mr. with following letters and ":" or

    Dr. med. with following letters and ":" or …

    My own favorite with a bit more security could be:

    [nvp]\.(\l{1,3}\.){0,2}\K[^:]+:

    With this grep false positive hits are possible but unlikely.

    Mugen777
    Mugen777Author
    Inspiring
    December 2, 2018

    pixxxel schubser

    Yeah, you are totally right but luckily my work is just like his example image.

    text v.t. testing: text text text.

    All lines like that, so it is working good. Otherwise, it could be a problem as you said.

    Sorry for not being clear at first (I should have said that all lines like this) and thank you again for effort and help : )

    pixxxelschubser
    Community Expert
    Community Expert
    December 2, 2018

    Can you embed the image here in the forum, please?

    While answering press this button for inserting a picture/image from your pc.

    Or maybe much more better: as plain text.

    Mugen777
    Mugen777Author
    Inspiring
    December 2, 2018

    n.f.

    n.f.pl.

    n.m.

    n.m.inv.

    n.m.pl.

    p.p.

    v.

    v.t.

    v.i.

    v.p.

    v.pr.

    v.imp.

    These are all of them, i don't know why i didn't write it directly first :/

    pixxxelschubser
    Community Expert
    Community Expert
    December 2, 2018

    one possible way

    [nvp]\.[fimpt]?[rm]?

    ?\.?[ip]?((l|nv)\.)?\K[^:]+:

    pixxxelschubser
    Community Expert
    Community Expert
    December 2, 2018

    Mugen777  schrieb

    … (I have abbreviations like "n.m.pl." as well, and i didn't even try them yet...)

    (Should i create a GREP style one by one? Is there an easier way?)

    How many grep styles do you use in your document?

    The more and the more complicated, the worse the performance of InDesign!!!

    [vn]\.[impt]r?\.(pl\.)?\K[^:]+:

    pixxxelschubser
    Community Expert
    Community Expert
    December 2, 2018

    A positive lookbehind is limited. You cannot find variable characters length.

    Better to use the (new) lookbehind \K instead.

    Try if this helps you out:

    v\.[ipt]r?\.\K[^:]+:

    Mugen777
    Mugen777Author
    Inspiring
    December 2, 2018

    Thank you for the answer

    Your code didn't include all of them (since there are more abbreviations) and i couldn't understand the code so i couldn't change it myself.

    Here, Imgur: The magic of the Internet these are all abbreviations.

    Is it possible to create one GREP code for them? Or maybe several?