8 Replies Latest reply on Dec 18, 2016 12:40 AM by Eugene Tyson

# Grep to find price duplicated?

Any GREP gurus help  me with the following

If the price is 100.00 followed by a tab and 100.00

That's what I want to find

1247.00 \t 1247.00

120.00 \t 120.00

10.00 \t 10.00

etc.

Basically if it's a number followed by two digits separated by a tab with the same number after the tab - that's what I want to find.

Any ideas?

• ###### 1. Re: Grep to find price duplicated?

Hi Eugene,

(\d+\.\d{2})\t\1

(^/)

• ###### 2. Re: Grep to find price duplicated?

Sweet! That was fast!

• ###### 3. Re: Grep to find price duplicated?

That was simple!

(^/)

• ###### 4. Re: Grep to find price duplicated?

Obi-wan, what does \1 mean, exactly according to GREP?

Is there a \2 and is there a \3 and is there a \4 and so on?

• ###### 5. Re: Grep to find price duplicated?

Hi Michael,

(a)\1 = … = (((((((((a)))))))))\9 = aa

(a)(b)\2 = abb

((a)(b))\2 = aba

\x makes back-reference to an item between parenthesis and its position in the code, and it replicates its contents!

1 … 9 only!

(^/)

• ###### 6. Re: Grep to find price duplicated?

Thank you Obi-wan; I didn't know that. I will add it to my GREP reference sheet:

• ###### 7. Re: Grep to find price duplicated?

Obi-wan Kenobi wrote:

Hi Michael,

(a)\1 = … = (((((((((a)))))))))\9 = aa

(a)(b)\2 = abb

((a)(b))\2 = aba

\x makes back-reference to an item between parenthesis and its position in the code, and it replicates its contents!

1 … 9 only!

(^/)

And as your first and third example are showing nicely \n is counting the opening parentheses from left to right and picks up the contents of the group that is opened by the \n found opening paranthesis:

(((a)(b)(c))(d))\1 = abcdabcd

(((a)(b)(c))(d))\2 = abcdabc
(((a)(b)(c))(d))\3 = abcda

(((a)(b)(c))(d))\4 = abcdb

(((a)(b)(c))(d))\5 = abcdc

(((a)(b)(c))(d))\6 = abcdd

If we go on with counting up \n nothing will be found, because there are not enough opening parantheses in my expression.

(((a)(b)(c))(d))\7 ≠

I wish there would be an error message saying:

"Error: There are only 6 opening parantheses in your expression!"

But instead the message is saying "No match found".

Regards,

Uwe

• ###### 8. Re: Grep to find price duplicated?

I was nearly there I could not get the repay to work when a Tab was involved,. I understand my error now and it was a while since I did Any grep.