Re: Find repeating substring



xhoster@xxxxxxxxx wrote:
"Mike" <msgrinnell@xxxxxxxxxxx> wrote:

Please don't top post. Top posting fixed.

xhoster@xxxxxxxxx wrote:
"Mike" <msgrinnell@xxxxxxxxxxx> wrote:
Hi All,

I need a regular expression to find repeating substrings (in
particular the substring that starts in position 1 of the string and
is repeated elsewhere in the string). For example, in the case
below, the substring of interest would be "HEART (CONDUCTION
DEFECT)".

Thanks much for any insights,

Mike

HEART (CONDUCTION DEFECT) 37.33/2 HEART (CONDUCTION DEFECT) WITH
CATHETER 37.34/2

This seems pretty simple. What am I missing?

/^(.*).*\1/s

Xho

Your solution still leaves the code 37.33/2 in the result.

No, it does not.


$ perl -l
$_ = 'HEART (CONDUCTION DEFECT) 37.33/2 HEART (CONDUCTION DEFECT)
WITH CATHETER 37.34/2';
if (/^(.*).*\1/) {
print "Result: $1";
}
__END__
Result: HEART (CONDUCTION DEFECT)

See, no 37.33/2 in the result!

Xho

--

Sorry. My mistake. I ran the Perl script with your suggestion and no
37.33/2 (as you noted). As I am trying to also see if this will work
in C# code (on demand) I ran it on Expresso as ^(.*).*\1 against the
same string and it left the code. Different implementation? I only
use regular expressions irregularly and so am merely dangerous with
them.

.


Loading