ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Duplicate phrases in one cell (https://www.excelbanter.com/excel-programming/428638-re-duplicate-phrases-one-cell.html)

Ron Rosenfeld

Duplicate phrases in one cell
 
On Mon, 18 May 2009 12:19:29 +0100, "Peter T" <peter_t@discussions wrote:

I don't fully follow the objective but based solely on your examples, it
looks like all you need to do is compare the left half with the right half.
You could do that with a VBA (could be a UDF) or with a simple formula, eg

=IF(LEFT(A1,LEN(A1)/2)=RIGHT(A1,LEN(A1)/2),LEFT(A1,LEN(A1)/2),A1)


Very simple, and neat.
--ron

randy

Duplicate phrases in one cell
 
On May 18, 1:45*pm, Ron Rosenfeld wrote:
On Mon, 18 May 2009 12:19:29 +0100, "Peter T" <peter_t@discussions wrote:
I don't fully follow the objective but based solely on your examples, it
looks like all you need to do is compare the left half with the right half.
You could do that with a VBA (could be a UDF) or with a simple formula, eg


=IF(LEFT(A1,LEN(A1)/2)=RIGHT(A1,LEN(A1)/2),LEFT(A1,LEN(A1)/2),A1)


Very simple, and neat.
--ron



Excellent solutions! I am happy to report that these work perfectly
for what I was wishing to do. I want to thank you guys very much for
the ingenuity.

Peter T

Duplicate phrases in one cell
 
"Ron Rosenfeld" wrote in message
=IF(LEFT(A1,LEN(A1)/2)=RIGHT(A1,LEN(A1)/2),LEFT(A1,LEN(A1)/2),A1)


Very simple, and neat.
--ron


Why thank you Ron.

Yours is very clever :-)

Regards,
Peter T



Ron Rosenfeld

Duplicate phrases in one cell
 
On Tue, 19 May 2009 11:34:01 +0100, "Peter T" <peter_t@discussions wrote:

Why thank you Ron.

Yours is very clever :-)

Regards,
Peter T


Mine uses Regular Expressions, and conceptually is doing the same thing as
yours. But a formulaic expression is usually much faster.

The only advantage to mine might be easy to change if the OP's requirements are
a bit different than posted.
--ron

Peter T

Duplicate phrases in one cell
 
"Ron Rosenfeld" wrote in message

Mine uses Regular Expressions, and conceptually is doing the same thing as
yours.
The only advantage to mine might be easy to change if the OP's
requirements are
a bit different than posted.


Would you care to explain how (if left-half = right-half)

re.Pattern = "^(.*)(\1)$"
mc = re.Execute(theString)

puts the left half in this
mc(0).submatches(1)

Regards,
Peter T



Ron Rosenfeld

Duplicate phrases in one cell
 
On Tue, 19 May 2009 22:26:31 +0100, "Peter T" <peter_t@discussions wrote:

Would you care to explain how (if left-half = right-half)

re.Pattern = "^(.*)(\1)$"
mc = re.Execute(theString)

puts the left half in this
mc(0).submatches(1)

Regards,
Peter T


I can try.

Actually, its the right half that's in mc(0).submatches(1), but since the right
and left halves are the same, it doesn't matter. The left half would be in
mc(0).submatches(0).

The pattern defines what is matched as follows:

------------------------
Paired phrases

^(.*)(\1)$

Assert position at the beginning of the string «^»
Match the regular expression below and capture its match into backreference
number 1 «(.*)»
Match any single character that is not a line break character «.*»
Between zero and unlimited times, as many times as possible, giving back
as needed (greedy) «*»
Match the regular expression below and capture its match into backreference
number 2 «(\1)»
Match the same text as most recently matched by capturing group number 1
«\1»
Assert position at the end of the string (or before the line break at the end
of the string, if any) «$»


Created with RegexBuddy
----------------------------

Since the pattern includes the beginning and end of the line, it will only
match if the left half = the right half.

Then it's just a matter of returning one, or the other.

See these references regarding Regular Expressions. They are from my
bookmarks; hopefully some of them are still good!

Regular Expressions
http://www.regular-expressions.info/reference.html
http://support.microsoft.com/default...02&Product=vbb
http://msdn2.microsoft.com/en-us/library/6wzad2b2.aspx
http://msdn2.microsoft.com/en-us/library/ms974619.aspx
http://www.regex-guru.info/
--ron

Peter T

Duplicate phrases in one cell
 
Thanks for that Ron, it helps.
One of these days I'll try and get to grips with it, might need to get into
a certain frame of mind first !

Regards,
Peter T




All times are GMT +1. The time now is 02:49 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com