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

Need GREP To Identify Multiple Patterns

Explorer ,
Oct 21, 2014 Oct 21, 2014

Hi

I am attempting to format text by identifying it with GREP patterns, then applying styles via InDesign's paragraph and character styles. I was able to get half of what I wanted using Nested Styles, but that solution doesn't seem to fit most of the cases in the files with which I am working. Here are the patterns I am trying to identify in a single GREP statement::

00% OFF

Over 00% OFF

$00.00

00.00

One of the above four patterns will always appear at the beginning of the paragraph. I want the GREP statement to identify the text that matches any or all of those patterns, so that I can apply the text styles. I was able get partially there by doing the first two "% OFF" scenarios using nested styles, then trying to do the "$00.00" and "00.00" with a GREP statement. I could never get the grep statement to completely work. Either it would ignore the "$" sign, or the first two digits before the decimal place. And I'm not even sure mixing Nested Styles and GREP is a wise way to go. Can someone assist me in getting a GREP statement that will identify any of these potential combinations. The document I am working on has other patterns that differ from the four above, but if I can get the above four, that will be about 80% off the project, and will minimize a lot of hand editing to get the font treatments correct.

Thanks in advance for any help you can lend on this.

TOPICS
Scripting
2.4K
Translate
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

Enthusiast , Oct 22, 2014 Oct 22, 2014

Hi,

try the following:

(Over )?\d+% OFF|\x24?\d+\.\d+

or if you want to find those combinations only at the beginning of a paragph:

^((Over )?\d+% OFF|\x24?\d+\.\d+)

– Kai

Translate
Mentor ,
Oct 22, 2014 Oct 22, 2014

Hi,

Are you looking for scripting solution or UI?

"$" and "." both are wildcards in GREP,so you have to escape them (in UI: "\$" and "\.") to make it working.

Jarek

Translate
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 ,
Oct 22, 2014 Oct 22, 2014

Hi,

try the following:

(Over )?\d+% OFF|\x24?\d+\.\d+

or if you want to find those combinations only at the beginning of a paragph:

^((Over )?\d+% OFF|\x24?\d+\.\d+)

– Kai

Translate
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
Explorer ,
Oct 22, 2014 Oct 22, 2014

Thank you so much for your help with this. I have another what seems to be an easy string to match that either partially works or fails altogether.

I have a phrase that follows the first expression - the phrase is "with your 25% savings pass!". There are variations of the phrase, but it always begins with the word "with", includes a % sign, and ends with a paragraph return. I read Peter Kahrel's "Automating InDesign with Regular Expressions"  and came up with this expression: with [A-Za-z0-9%]\r   That doesn't work at all. If i remove the end of paragraph, \r, then the expression partially works, identifying "with and the "y" in "your" but nothing else.  Am I messing a repeat 1 or more times character?

Translate
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
Explorer ,
Oct 22, 2014 Oct 22, 2014

OK, I think I've got it. Is the expression below the best way to match the phrase "with your 25% savings pass!". Again, there are variations of the phrase, but it always begins with the word "with", includes a % sign, and ends with a paragraph return.

with .*\r

Translate
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 ,
Oct 22, 2014 Oct 22, 2014
Am I messing a repeat 1 or more times character?

Yes. Everything in [] counts as one character. Instead of [A-Za-z0-9%]\r you coud also write [\w%]\r . This will find only the last character before the return. But this will not find spaces or dashes!

To find more you could use 'with .*\r' as you mentioned. But this will also find "with all my friends." followed by a return. So this is maybe not the best way.

If you know, that you have digits, followed by a space or not and a percentage character in your text, include it in your expression!

So this 'with.+\d+\s?%.+\r' will find "with your 25% savings pass!" followed by a return, but not "with all my 25 friends"

Translate
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
Explorer ,
Oct 22, 2014 Oct 22, 2014

Thanks again. This can get convoluted, so I appreciate the advice. Now I am seeing instances where the line "with your 25% savings pass!" has to be broken via a soft return (shift + return key) When broken, the second line no longer starts with the word "with", so the grep style is not applied to the new second line. Is there a way to tell a grep style to carry on through a soft return?

Translate
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 ,
Oct 22, 2014 Oct 22, 2014

Sure. Please make a screenshot from this part. It is then easier for me to give you the correct grep.

Translate
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
LEGEND ,
Oct 22, 2014 Oct 22, 2014

Hi,

Interesting grep:  ^with(\n?.)+\d+%(\n?.)+$

Translate
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
Explorer ,
Oct 22, 2014 Oct 22, 2014

Sample InDesign CS4 document is here

http://www.icestorm.net/theland/misc/grep_test.indd

Here is a screen shot of what happens when I do a hard or soft return

grep_question.gif

Translate
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 ,
Oct 22, 2014 Oct 22, 2014

Thanks for your samples. First of all, live isn’t always easy 😉

Apply some colors to your character styles and you will see, that your first style isn’t honored (OFF > off)

Second: It is a big difference for grepstyles, if you enter a softreturn in the same paragraph or you enter a hard return (new paragraph).

Since the scope of grepstyles is paragraph based, your second para did not know the first one.

So in your special example you could use (with|coupon)[^\r]+

That means, search for: with or coupon, followed by anything that is not a hard return, multiple times.

But if you have other phrases, this may not work or must be extended.

Bildschirmfoto 2014-10-23 um 08.04.20.png

Translate
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
Explorer ,
Dec 18, 2014 Dec 18, 2014
LATEST

Thanks everyone who helped me with the above question. I am getting more variance in the text that when I initially wrote. Here is a typical range of what would need to match with an expressions. Is this too free-form for a grep expression? Any ideas on this would be appreciated.

00% OFF

Over 00% OFF

$00.00

00.00

Up to 00% off

$00 off

000.00

$00-$00

Translate
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