GREP Apply strikethrough to Prices only

Home Forums General InDesign Topics GREP Apply strikethrough to Prices only

Tagged: ,

This topic contains 4 replies, has 2 voices, and was last updated by  Glen Hart 2 months, 1 week ago.

  • Author
  • #100904

    Glen Hart

    Hi Guys, Hope you can help, I’m fairly new to the GREP’s but am trying to apply a strikethough to any prices in the following formats, but ONLY IF they follow on from the letter PM.

    PM £X
    PM £X.XX
    PM £XX
    PM £XX.XX

    I have come up with the following which works when i’m just changing the text color but when I apply the strikethrough to the character style it then strikes through to the entire line, in addition it also seems to apply it to other prices elsewhere in the document even though they don’t come after the letters “PM”.

    (?<=[PM]\s)(£\d+)|(£\d+.\d+) this doesn’t work at all but i thought it should
    (?<=[PM]\s)£\d+ without pence (works when adjusting font color)
    (?<=[PM]\s)£\d+.\d+ with pence (works when adjusting font color)

    Thank you in advance and appreciate any help you can offer :).

  • #100907

    Hi Glen, this seems to works fine:
    (?<=PM )£\d+\.?(\d+)*

    (?<=PM ) without square brackets
    £\d+\.?(\d+)* this apply the format to the prices

    Let try it

  • #100909

    Glen Hart

    Hi Claudio, thank you I really appreciate this.. That works perfectly! Can I ask what the question mark and star do at the end


    Is this a wildcard of some sort?

  • #100910

    Of course you can!

    ? and * are relative to the preceding character

    \.? means literal period 0 or 1 time (either case GREP find the match)
    (\d+)*, or better \d* means figure 0 or multiple times

  • #100911

    Glen Hart

    Thank you very much! Have a lovely day :)

You must be logged in to reply to this topic.