Re: Regex expert needed??

2019-08-26 Thread Chip Scheide via 4D_Tech
Update  :

the following code should be more efficient for getting the actual 
substring(s) replacing the loop starting "For($i;1;$Size)". 

The following code, uses the built up 2D array to determine where the 
longest substring(s) end, this gives a position in the shorter string 
where the common string ends. Then we 'walk backwards' over the shorter 
string by common string length -1 to build the common substring(s).
This avoids a lot of thrashing with position and substring.

ARRAY TEXT($aMatch;0)


For ($i;1;$m)  //$m - is length of shorter string/dimension of 2D array
$Found:=Find in array($LCSub{$i};$longest)

If ($Found>0)
$string:=""

For ($j;1;$longest)  //Build up the common substring
$String:=$shorter[[$Found-$j+1]]+$string
End for 
append to array($aMatch;$String)  // add to array to return
End if 
End for 


On Mon, 26 Aug 2019 13:55:02 -0400, Chip Scheide via 4D_Tech wrote:
> Keith,
> Thanks for you input!!
> we seem to have a nice collaboration on text utilities  :)
> 
> I ran the code you provided, and found an issue.
> Given:
> "This is my dog" & "My Dog does not have fleas"
> 
> - Your initial code generates NO matches - you use Position with Case 
> sensitivity ON, and as for position > 1, missing matches starting at 
> position 1.
> - With out case sensitivity, & Position > 0, Your code generates the 
> longest common string as length 5, and "my do"
> This is because you end up truncating the last character comparison due 
> to using [[$i-1]] 
> 
> Follows, modified code to handle requests for both case sensitivity, 
> and not, as well as removing the truncation issue.
> 
> 
> I am thinking that it might be slightly more efficient to:
> - compare the first 2 characters -- removing 1 iteration over the 
> longer string. But it might not be worth the housekeeping to code that.
> - to build the final longest string as you go, rather then reiterate 
> back over the strings looking for matches of the longest length.  
> Where X = the number of times the longest common string length can be 
> found in the shortest string... it would save X substrings, 2X 
> positions X find in array, 2X assignments, and 2X comparisons + the 
> loop counter incrementation and comparison.
> 
> 
> For relatively short strings, there would likely be no significant 
> difference in execution time, however, very long strings (what length 
> is 'long' I do not know), or repeated execution of this code in some 
> sort of loop the difference might be large.
> 
> 
> Code start::
> 
>// 
>   // Method: Suffix_Tree - from Wiki examples
>   // - 
>   // INPUT1: Text - to compare
>   // INPUT2: Text - to compare
>   // INPUT3: Pointer - array of longest matches
>   // INPUT4: Boolean - Do case sensitive comparisons (default = false)
>   // OUTPUT: Longint - length 
>   //  
> C_LONGINT($i;$size;$longest;$0)
> C_TEXT($longer;$shorter;$temp)
> C_POINTER($3;$Return_Array)
> C_BOOLEAN($4;$Case_Sensitive;$Same)
> $str1:=$1
> $str2:=$2
> $Return_Array:=$3
> 
> If (Count parameters>=4)
> $Case_Sensitive:=$4
> End if 
> 
> If (Length($str1)>Length($str2))
> $longer:=$str1
> $shorter:=$str2
> Else 
> $longer:=$str2
> $shorter:=$str1
> End if 
> 
> $m:=Length($longer)  // is the longer string
> $n:=Length($shorter)
> 
> ARRAY LONGINT($LCSub;$m;$n)
> $longest:=0
> 
> For ($i;1;$m)
> For ($j;1;$n)
> 
> If ($Case_Sensitive)  //doing case sensitive comparision - yes
> $Same:=(Character code($longer[[$i]])=Character code($shorter[[$j]]))
> Else   //- no
> $Same:=($longer[[$i]]=$shorter[[$j]])
> End if 
> 
> If ($Same)  //are the current strings the same? - yes
> 
>   //depending on the comparision point add this character count
> Case of 
> : ($i=1)
> $LCSub{$i}{$j}:=$LCSub{$i}{$j}+1
> : ($j=1)
> $LCSub{$i}{$j}:=$LCSub{$i-1}{$j}+1
> Else 
> $LCSub{$i}{$j}:=$LCSub{$i-1}{$j-1}+1
> End case 
> 
>   //longer then the previous longest?
> If ($longest<$LCSub{$i}{$j})  //
> $longest:=$LCSub{$i}{$j}  //update the longest substring found
> End if 
> Else 
> $LCSub{$i}{$j}:=0
> End if 
> 
> End for 
> End for 
> 
>   // search for matches of $longest length
> ARRAY TEXT($aMatch;0)
> $size:=Length($shorter)-$longest+1
> 
>   //for every possible substring of the longest length
>   //try to find substring matches
> For ($i;1;$size)
> $temp:=Substring($shorter;$i;$longest)
> 
> If ($Case_Sensitive)  //case sensitive comparison - Yes
> $Found:=Position($temp;$longer;*)
> Else   //-no
> $Found:=Position($temp;$longer)
> End if 
> 
> If ($Found>0)  //note was >1
> 
>   //hve we found this substrig before?
> If (Find in array($aMatch;$temp)=-1)
> APPEND TO ARRAY($aMatch;$temp)  //- no
> End if 
> End if 
> End for 
> 
> COPY ARRAY($aMatch;$Return_Array->)
> $0:=$longest
> 
> 
> On Sat, 24 Aug 2019 16:23:56 -0500, Keith Culotta via 4D_Tech wrote:
>> That's great.  It's fast, and reduces the number of searches.
>> 
>> Keith - CDI
>> 
>> 
>>   // 

Re: Regex expert needed??

2019-08-26 Thread Chip Scheide via 4D_Tech
Keith,
Thanks for you input!!
we seem to have a nice collaboration on text utilities  :)

I ran the code you provided, and found an issue.
Given:
"This is my dog" & "My Dog does not have fleas"

- Your initial code generates NO matches - you use Position with Case 
sensitivity ON, and as for position > 1, missing matches starting at 
position 1.
- With out case sensitivity, & Position > 0, Your code generates the 
longest common string as length 5, and "my do"
This is because you end up truncating the last character comparison due 
to using [[$i-1]] 

Follows, modified code to handle requests for both case sensitivity, 
and not, as well as removing the truncation issue.


I am thinking that it might be slightly more efficient to:
- compare the first 2 characters -- removing 1 iteration over the 
longer string. But it might not be worth the housekeeping to code that.
- to build the final longest string as you go, rather then reiterate 
back over the strings looking for matches of the longest length.  
Where X = the number of times the longest common string length can be 
found in the shortest string... it would save X substrings, 2X 
positions X find in array, 2X assignments, and 2X comparisons + the 
loop counter incrementation and comparison.


For relatively short strings, there would likely be no significant 
difference in execution time, however, very long strings (what length 
is 'long' I do not know), or repeated execution of this code in some 
sort of loop the difference might be large.


Code start::

   // 
  // Method: Suffix_Tree - from Wiki examples
  // - 
  // INPUT1: Text - to compare
  // INPUT2: Text - to compare
  // INPUT3: Pointer - array of longest matches
  // INPUT4: Boolean - Do case sensitive comparisons (default = false)
  // OUTPUT: Longint - length 
  //  
C_LONGINT($i;$size;$longest;$0)
C_TEXT($longer;$shorter;$temp)
C_POINTER($3;$Return_Array)
C_BOOLEAN($4;$Case_Sensitive;$Same)
$str1:=$1
$str2:=$2
$Return_Array:=$3

If (Count parameters>=4)
$Case_Sensitive:=$4
End if 

If (Length($str1)>Length($str2))
$longer:=$str1
$shorter:=$str2
Else 
$longer:=$str2
$shorter:=$str1
End if 

$m:=Length($longer)  // is the longer string
$n:=Length($shorter)

ARRAY LONGINT($LCSub;$m;$n)
$longest:=0

For ($i;1;$m)
For ($j;1;$n)

If ($Case_Sensitive)  //doing case sensitive comparision - yes
$Same:=(Character code($longer[[$i]])=Character code($shorter[[$j]]))
Else   //- no
$Same:=($longer[[$i]]=$shorter[[$j]])
End if 

If ($Same)  //are the current strings the same? - yes

  //depending on the comparision point add this character count
Case of 
: ($i=1)
$LCSub{$i}{$j}:=$LCSub{$i}{$j}+1
: ($j=1)
$LCSub{$i}{$j}:=$LCSub{$i-1}{$j}+1
Else 
$LCSub{$i}{$j}:=$LCSub{$i-1}{$j-1}+1
End case 

  //longer then the previous longest?
If ($longest<$LCSub{$i}{$j})  //
$longest:=$LCSub{$i}{$j}  //update the longest substring found
End if 
Else 
$LCSub{$i}{$j}:=0
End if 

End for 
End for 

  // search for matches of $longest length
ARRAY TEXT($aMatch;0)
$size:=Length($shorter)-$longest+1

  //for every possible substring of the longest length
  //try to find substring matches
For ($i;1;$size)
$temp:=Substring($shorter;$i;$longest)

If ($Case_Sensitive)  //case sensitive comparison - Yes
$Found:=Position($temp;$longer;*)
Else   //-no
$Found:=Position($temp;$longer)
End if 

If ($Found>0)  //note was >1

  //hve we found this substrig before?
If (Find in array($aMatch;$temp)=-1)
APPEND TO ARRAY($aMatch;$temp)  //- no
End if 
End if 
End for 

COPY ARRAY($aMatch;$Return_Array->)
$0:=$longest


On Sat, 24 Aug 2019 16:23:56 -0500, Keith Culotta via 4D_Tech wrote:
> That's great.  It's fast, and reduces the number of searches.
> 
> Keith - CDI
> 
> 
>   // 
>   // Method: Suffix_Tree - from Wiki examples
>   // - 
>   // INPUT1: Text - to compare
>   // INPUT2: Text - to compare
>   // INPUT3: Pointer - array of longest matches
>   // OUTPUT: Longint - length 
>   //  
> C_LONGINT($i;$size;$longest;$0)
> C_TEXT($longer;$shorter;$temp)
> $str1:=$1
> $str2:=$2
> 
> If (Length($str1)>Length($str2))
>   $longer:=$str1
>   $shorter:=$str2
> Else 
>   $longer:=$str2
>   $shorter:=$str1
> End if 
> 
> $m:=Length($longer)  // is the longer string
> $n:=Length($shorter)
> 
> ARRAY LONGINT($LCSub;$m;$n)
> $longest:=0
> 
> For ($i;1;$m)
>   For ($j;1;$n)
>   If ($i=1) | ($j=1)
>   $LCSub{$i}{$j}:=0
> 
>   Else 
>   If ($longer[[$i-1]]=$shorter[[$j-1]])
>   $LCSub{$i}{$j}:=$LCSub{$i-1}{$j-1}+1
>   If ($longest<$LCSub{$i}{$j})
>   $longest:=$LCSub{$i}{$j}
>   End if 
>   Else 
>

Re: Regex expert needed??

2019-08-24 Thread Kirk Brooks via 4D_Tech
Maybe they do actually read the nug:

https://kb.4d.com/assetid=78301

On Thu, Aug 22, 2019 at 1:13 PM Chip Scheide via 4D_Tech <
4d_tech@lists.4d.com> wrote:

> Given 2 strings,
> I want to find, and return, the longest substring which is the same in
> both, regardless where in either string the longest substring starts.
>
> ex:
> 1- This is my dog
> 2- My dog does not have fleas
> longest common string is 'my dog'
>
> how to go about this, efficiently?
> I am assuming that there is regex black magic that would do this.
>
> ---
> Gas is for washing parts
> Alcohol is for drinkin'
> Nitromethane is for racing
> **
> 4D Internet Users Group (4D iNUG)
> Archive:  http://lists.4d.com/archives.html
> Options: https://lists.4d.com/mailman/options/4d_tech
> Unsub:  mailto:4d_tech-unsubscr...@lists.4d.com
> **



-- 
Kirk Brooks
San Francisco, CA
===

What can be said, can be said clearly,
and what you can’t say, you should shut up about

*Wittgenstein and the Computer *
**
4D Internet Users Group (4D iNUG)
Archive:  http://lists.4d.com/archives.html
Options: https://lists.4d.com/mailman/options/4d_tech
Unsub:  mailto:4d_tech-unsubscr...@lists.4d.com
**

Re: Regex expert needed??

2019-08-24 Thread Keith Culotta via 4D_Tech
That's great.  It's fast, and reduces the number of searches.

Keith - CDI


  // 
  // Method: Suffix_Tree - from Wiki examples
  // - 
  // INPUT1: Text - to compare
  // INPUT2: Text - to compare
  // INPUT3: Pointer - array of longest matches
  // OUTPUT: Longint - length 
  //  
C_LONGINT($i;$size;$longest;$0)
C_TEXT($longer;$shorter;$temp)
$str1:=$1
$str2:=$2

If (Length($str1)>Length($str2))
$longer:=$str1
$shorter:=$str2
Else 
$longer:=$str2
$shorter:=$str1
End if 

$m:=Length($longer)  // is the longer string
$n:=Length($shorter)

ARRAY LONGINT($LCSub;$m;$n)
$longest:=0

For ($i;1;$m)
For ($j;1;$n)
If ($i=1) | ($j=1)
$LCSub{$i}{$j}:=0

Else 
If ($longer[[$i-1]]=$shorter[[$j-1]])
$LCSub{$i}{$j}:=$LCSub{$i-1}{$j-1}+1
If ($longest<$LCSub{$i}{$j})
$longest:=$LCSub{$i}{$j}
End if 
Else 
$LCSub{$i}{$j}:=0
End if 
End if 

End for 
End for 

  // search for matches of $longest length
ARRAY TEXT($aMatch;0)
$size:=Length($shorter)-$longest+1
For ($i;1;$size)
$temp:=Substring($shorter;$i;$longest)
If (Position($temp;$longer;*)>1)
If (Find in array($aMatch;$temp)=-1)
APPEND TO ARRAY($aMatch;$temp) 
End if 
End if 
End for 

COPY ARRAY($aMatch;$3->)
$0:=$longest




> On Aug 24, 2019, at 2:41 PM, John DeSoi via 4D_Tech <4d_tech@lists.4d.com> 
> wrote:
> 
> See 
> 
> https://en.wikipedia.org/wiki/Longest_common_substring_problem
> 
> John DeSoi, Ph.D.
> 
> 
>> On Aug 24, 2019, at 10:48 AM, Keith Culotta via 4D_Tech 
>> <4d_tech@lists.4d.com> wrote:
>> 
>> This version stands alone, and runs a little more efficiently.  It's not 
>> been tested in every way, but the results are encouraging.  Interesting 
>> problem.  I can't think of a way to do it without comparing every character 
>> combination.  The new "Split string" command would speed part of this up if 
>> Collections could be used.
> 

**
4D Internet Users Group (4D iNUG)
Archive:  http://lists.4d.com/archives.html
Options: https://lists.4d.com/mailman/options/4d_tech
Unsub:  mailto:4d_tech-unsubscr...@lists.4d.com
**

Re: Regex expert needed??

2019-08-24 Thread John DeSoi via 4D_Tech
See 

https://en.wikipedia.org/wiki/Longest_common_substring_problem

John DeSoi, Ph.D.


> On Aug 24, 2019, at 10:48 AM, Keith Culotta via 4D_Tech 
> <4d_tech@lists.4d.com> wrote:
> 
> This version stands alone, and runs a little more efficiently.  It's not been 
> tested in every way, but the results are encouraging.  Interesting problem.  
> I can't think of a way to do it without comparing every character 
> combination.  The new "Split string" command would speed part of this up if 
> Collections could be used.

**
4D Internet Users Group (4D iNUG)
Archive:  http://lists.4d.com/archives.html
Options: https://lists.4d.com/mailman/options/4d_tech
Unsub:  mailto:4d_tech-unsubscr...@lists.4d.com
**

Re: Regex expert needed??

2019-08-24 Thread Keith Culotta via 4D_Tech
This version stands alone, and runs a little more efficiently.  It's not been 
tested in every way, but the results are encouraging.  Interesting problem.  I 
can't think of a way to do it without comparing every character combination.  
The new "Split string" command would speed part of this up if Collections could 
be used.

Keith - CDI


$str1:="kaslfkshjflsfhlksadlfbskdjfblgiutgqoiwuflkfhaskhjfgkajshgaefgasjdfgkajshgfakjhgfuyf"
$str2:="askjfhaskfhlhflefhljksfhdlkjdshfljkhflsehflifhlksjdfhljhsaljdiodjejkljfhlajksdhflajsdhfljdhflkajhdsflwuhfl"
ARRAY TEXT($aMatch;0)
$longest:=getCommon2 ($str1;$str2;->$aMatch)
ALERT($longest)  // = fhask



  // 
  // Method: getCommon2
  // - 
  // INPUT1: Text - to compare characters
  // INPUT2: Text - to compare characters
  // INPUT3: Pointer - to text array of all common character strings
  // OUTPUT: Text - a longest match
  // 
C_TEXT($str1;$str2;$str3;$1;$2;$0;$longestFound;$longer;$shorter;$sepChar2;$padStr;$sepChar;$word)
C_LONGINT($i;$j;$longLen;$loop;$m;$pos1;$pos2;$shortLen;$size;$newStart;$start)

$str1:=$1
$str2:=$2
$sepChar:="‡"  //Char(4)  // any character that would not be in the string
$longestFound:=""

If (Length($str1)>Length($str2))
$longer:=$str1
$shorter:=$str2
Else 
$longer:=$str2
$shorter:=$str1
End if 

$shortLen:=Length($shorter)
$padStr:=$sepChar*$shortLen
$longer:=$padStr+$longer
$longLen:=Length($longer)
$loop:=1
ARRAY TEXT($aMatch;0)

Repeat 
Case of 
: ($loop<=$shortLen)  // starting
$pos1:=$shortLen
$pos2:=$shortLen+$loop
: ($loop>=$shortLen) & (($shortLen+$loop)<=$longLen)
$pos1:=$loop
$pos2:=$shortLen+$loop
Else 
$pos1:=$loop
$pos2:=$longLen
End case 

$shorter:=$sepChar+$shorter  // slide str1 over str2
$str3:=$sepChar*($pos2)

For ($i;$pos1;$pos2)  // compare the vertical chars
For ($j;$pos1;$i)
If ($shorter[[$j]]=$longer[[$j]])
$str3[[$j]]:=$shorter[[$j]]  // record a match
End if 
End for 
End for 

  // - break out the matches
$start:=1
ARRAY TEXT($aTemp;0)
$sepChar2:=$sepChar+$sepChar

Repeat 
$str3:=Replace string($str3;$sepChar2;$sepChar;*)  // remove 
all but a single sepChar
Until (Position($sepChar2;$str3;*)=0)  // still need to check for the 
sepChar at the beginning or end?

Repeat 
$newStart:=Position($sepChar;$str3;$start;*)
If ($newStart=0)
$word:=Substring($str3;$start)  // get the last word
Else 
$word:=Substring($str3;$start;$newStart-$start)
End if 
APPEND TO ARRAY($aTemp;$word)
$start:=$newStart+1
Until ($newStart=0)
  // - break out the matches

$size:=Size of array($aTemp)
For ($m;1;$size)
If (Find in array($aMatch;$aTemp{$m})=-1)  // add the match if 
it's not already there
APPEND TO ARRAY($aMatch;$aTemp{$m})
If (Length($aTemp{$m})>Length($longestFound))  // 
remember the longest 
$longestFound:=$aTemp{$m}
End if 
End if 
End for 

$loop:=$loop+1

Until ($pos1>$longLen)
  // | (Length($longestFound)>($longLen-$pos1))
  // could  stop when the greatest found length exceeds the # of chars 
remaining to check
  // if the complete array is not needed

COPY ARRAY($aMatch;$3->)
$0:=$longestFound



> On Aug 23, 2019, at 8:27 AM, Chip Scheide via 4D_Tech <4d_tech@lists.4d.com> 
> wrote:
> 
> 
> well...
> if there is a double space in one and not the other then the longest 
> duplicated string would be ' dog'.
> So that answer would be correct.
> 
> Also, over all, I would be interested in character duplication rather then 
> word duplication.
> 
> Thanks
> for all the input!!
> 
> Chip
> 
>> That’s rather what I thought, in which case it won’t work for Chip’
>> s original query.
>> 
>>> On 22 Aug 2019, at 21:12, Chip Scheide via 4D_Tech 
>>> <4d_tech@lists.4d.com> wrote:
>>> 
>>> Given 2 strings, 
>>> I want to find, and return, the longest substring which is the same in 
>>> both, regardless where in either string the longest substring starts.
>>> 
>>> ex: 
>>> 1- This is my dog
>>> 2- My dog does not have fleas
>>> longest common string is 'my dog’
>> 
>> 1 - This is my  dog// note double space after 
>> “my” 
>> 2 - My dog does not have fleas
>> 
>> longest common 

Re: Regex expert needed??

2019-08-23 Thread Keith Culotta via 4D_Tech
This behaves better, in that it works for the whole of both strings.  It could 
still be optimized.  The array that gets returned has all (afaict) the matches.


$str1:="This is my dog"
$str2:="My dog does not have fleas"
  //$str2:="My dog does not have fleas" 

  //$str1:="The quick brown fox jumps over the lazy dog"
  //$str2:="The quick black fox leaps over the laziest dog"

  //$str1:="The quick brownbrown fox jumps over the lazy dog"
  //$str2:="fox leaps over the laziest dog The quick brownbrown"

ARRAY TEXT($aMatch;0)
getCommon2 ($str1;$str2;->$aMatch)

SORT ARRAY($aMatch;<)



  // 
  // Method: getCommon2
  // - 
  // INPUT1: Text
  // INPUT2: Text
  // INPUT3: Pointer - to text array
  // OUTPUT: 
  // 


$str1:=$1
$str2:=$2
$unique:=True
$sepChar:=Char(9)

If (Length($str1)>Length($str2))
$longer:=$str1
$shorter:=$str2
Else 
$longer:=$str2
$shorter:=$str1
End if 

$shortLen:=Length($shorter)
$padStr:=$sepChar*$shortLen
$shorter:=$shorter
$longer:=$padStr+$longer

$longLen:=Length($longer)
$maxLen:=$shortLen*2+$longLen

$loop:=1

ARRAY TEXT($aMatch;0)

Repeat 
Case of 
: ($loop<=$shortLen)  // starting
$pos1:=$shortLen
$pos2:=$shortLen+$loop
: ($loop>=$shortLen) & (($shortLen+$loop)<=$longLen)
$pos1:=$loop
$pos2:=$shortLen+$loop
Else 
$pos1:=$loop
$pos2:=$longLen
End case 

$shorter:=$sepChar+$shorter  // push str1 onto str2
$str3:=$sepChar*($pos2)  // longer than needed?

For ($i;$pos1;$pos2)
For ($j;$pos1;$i)
If ($shorter[[$j]]=$longer[[$j]])
$str3[[$j]]:=$shorter[[$j]]
End if 
End for 
ARRAY TEXT($aTemp;0)
Parse_TextToArray ($str3;->$aTemp;$sepChar;$unique)  // as if 
GET TEXT KEYWORDS let you pick the separator
End for 

$size:=Size of array($aTemp)
For ($m;1;$size)
If (Find in array($aMatch;$aTemp{$m})=-1)
APPEND TO ARRAY($aMatch;$aTemp{$m})
End if 
End for 

$loop:=$loop+1
Until ($pos1>$longLen)

COPY ARRAY($aMatch;$3->)

Keith - CDI

> On Aug 22, 2019, at 3:12 PM, Chip Scheide via 4D_Tech <4d_tech@lists.4d.com> 
> wrote:
> 
> Given 2 strings, 
> I want to find, and return, the longest substring which is the same in 
> both, regardless where in either string the longest substring starts.
> 
> ex: 
> 1- This is my dog
> 2- My dog does not have fleas
> longest common string is 'my dog'
> 
> how to go about this, efficiently?
> I am assuming that there is regex black magic that would do this.
>  

**
4D Internet Users Group (4D iNUG)
Archive:  http://lists.4d.com/archives.html
Options: https://lists.4d.com/mailman/options/4d_tech
Unsub:  mailto:4d_tech-unsubscr...@lists.4d.com
**

Re: Regex expert needed??

2019-08-23 Thread Keith Culotta via 4D_Tech
I realize you said "efficiently", but if you ever miss that old Bubble Sort 
feeling...

$str1:="This is my dog"
$str2:="My dog does not have fleas"

$str1:="The quick brown fox jumps over the lazy dog"
$str2:="The quick black fox leaps over the laziest dog"

ARRAY TEXT($aMatch;0)
getCommon ($str1;$str2;->$aMatch)

SORT ARRAY($aMatch;<)


  // 
  // Method: getCommon - needs some optimization
  // - 
  // INPUT1: Text
  // INPUT2: Text
  // INPUT3: Pointer - to text array
  // OUTPUT: 
  // 
$str1:=$1
$str2:=$2

If (Length($str1)>Length($str2))
$longer:=$str1
$shorter:=$str2
Else 
$longer:=$str2
$shorter:=$str1
End if 

$shortLen:=Length($shorter)
$longLen:=Length($longer)
$maxLen:=$shortLen*2+$longLen
$loop:=1
$buildText:=""

Repeat 
ARRAY TEXT($aMatch;0)
For ($i;1;$loop)
$str1:=Substring($shorter;$shortLen-$i)
$str2:=Substring($longer;1;$loop+1)

For ($j;1;Length($str1))
If ($str1[[$j]]=$str2[[$j]])
$buildText:=$buildText+$str1[[$j]]
Else 
APPEND TO ARRAY($aMatch;$buildText)
$buildText:=" "
End if 
End for 

End for 
$loop:=$loop+1
Until ($loop>$maxLen)
 
COPY ARRAY($aMatch;$3->)


Keith - CDI

> On Aug 22, 2019, at 3:12 PM, Chip Scheide via 4D_Tech <4d_tech@lists.4d.com> 
> wrote:
> 
> Given 2 strings, 
> I want to find, and return, the longest substring which is the same in 
> both, regardless where in either string the longest substring starts.
> 
> ex: 
> 1- This is my dog
> 2- My dog does not have fleas
> longest common string is 'my dog'
> 
> how to go about this, efficiently?
> I am assuming that there is regex black magic that would do this.
>  

**
4D Internet Users Group (4D iNUG)
Archive:  http://lists.4d.com/archives.html
Options: https://lists.4d.com/mailman/options/4d_tech
Unsub:  mailto:4d_tech-unsubscr...@lists.4d.com
**

Re: Regex expert needed??

2019-08-23 Thread Chip Scheide via 4D_Tech

well...
if there is a double space in one and not the other then the longest duplicated 
string would be ' dog'.
So that answer would be correct.

Also, over all, I would be interested in character duplication rather then word 
duplication.

Thanks
for all the input!!

Chip

> That’s rather what I thought, in which case it won’t work for Chip’
> s original query.
> 
>> On 22 Aug 2019, at 21:12, Chip Scheide via 4D_Tech 
>> <4d_tech@lists.4d.com> wrote:
>> 
>> Given 2 strings, 
>> I want to find, and return, the longest substring which is the same in 
>> both, regardless where in either string the longest substring starts.
>> 
>> ex: 
>> 1- This is my dog
>> 2- My dog does not have fleas
>> longest common string is 'my dog’
> 
> 1 - This is my  dog// note double space after 
> “my” 
> 2 - My dog does not have fleas
> 
> longest common string is “ dog “ (and in Chip’s example, it’s 
> actually “my dog “).
> 
> Jeremy
> 
>> On 23 Aug 2019, at 13:46, Keisuke Miyako via 4D_Tech 
>> <4d_tech@lists.4d.com> wrote:
>> 
>> GET TEXT KEYWORDS breaks strings the same way as when you 
>> double-click a word in a text editor.
>> 
>> spaces, tabs, etc. are boundaries,
>> commas periods and apostrophes depend on the context.
>> 
>> e.g. (one word)
>> 1,000,000 (one word)
>> Macy's (one word)
>> 
>> http://userguide.icu-project.org/boundaryanalysis
>> 
>> 2019/08/23 21:39、Jeremy Roussak via 4D_Tech 
>> <4d_tech@lists.4d.com>のメール:
>> What about double spaces?
> **
> 4D Internet Users Group (4D iNUG)
> Archive:  http://lists.4d.com/archives.html
> Options: https://lists.4d.com/mailman/options/4d_tech
> Unsub:  mailto:4d_tech-unsubscr...@lists.4d.com
> **

Hell is other people 
 Jean-Paul Sartre
**
4D Internet Users Group (4D iNUG)
Archive:  http://lists.4d.com/archives.html
Options: https://lists.4d.com/mailman/options/4d_tech
Unsub:  mailto:4d_tech-unsubscr...@lists.4d.com
**

Re: Regex expert needed??

2019-08-23 Thread Jeremy Roussak via 4D_Tech
That’s rather what I thought, in which case it won’t work for Chip’s original 
query.

> On 22 Aug 2019, at 21:12, Chip Scheide via 4D_Tech <4d_tech@lists.4d.com> 
> wrote:
> 
> Given 2 strings, 
> I want to find, and return, the longest substring which is the same in 
> both, regardless where in either string the longest substring starts.
> 
> ex: 
> 1- This is my dog
> 2- My dog does not have fleas
> longest common string is 'my dog’

1 - This is my  dog// note double space after “my” 
2 - My dog does not have fleas

longest common string is “ dog “ (and in Chip’s example, it’s actually “my dog 
“).

Jeremy

> On 23 Aug 2019, at 13:46, Keisuke Miyako via 4D_Tech <4d_tech@lists.4d.com> 
> wrote:
> 
> GET TEXT KEYWORDS breaks strings the same way as when you double-click a word 
> in a text editor.
> 
> spaces, tabs, etc. are boundaries,
> commas periods and apostrophes depend on the context.
> 
> e.g. (one word)
> 1,000,000 (one word)
> Macy's (one word)
> 
> http://userguide.icu-project.org/boundaryanalysis
> 
> 2019/08/23 21:39、Jeremy Roussak via 4D_Tech 
> <4d_tech@lists.4d.com>のメール:
> What about double spaces?
**
4D Internet Users Group (4D iNUG)
Archive:  http://lists.4d.com/archives.html
Options: https://lists.4d.com/mailman/options/4d_tech
Unsub:  mailto:4d_tech-unsubscr...@lists.4d.com
**

Re: Regex expert needed??

2019-08-23 Thread Keisuke Miyako via 4D_Tech
GET TEXT KEYWORDS breaks strings the same way as when you double-click a word 
in a text editor.

spaces, tabs, etc. are boundaries,
commas periods and apostrophes depend on the context.

e.g. (one word)
1,000,000 (one word)
Macy's (one word)

http://userguide.icu-project.org/boundaryanalysis

2019/08/23 21:39、Jeremy Roussak via 4D_Tech 
<4d_tech@lists.4d.com>のメール:
What about double spaces?



**
4D Internet Users Group (4D iNUG)
Archive:  http://lists.4d.com/archives.html
Options: https://lists.4d.com/mailman/options/4d_tech
Unsub:  mailto:4d_tech-unsubscr...@lists.4d.com
**

Re: Regex expert needed??

2019-08-23 Thread Jeremy Roussak via 4D_Tech
What about double spaces?

Jeremy

> On 23 Aug 2019, at 13:28, Kirk Brooks via 4D_Tech <4d_tech@lists.4d.com> 
> wrote:
> 
> Arnaud,
> Good point. If collections aren't available GET TEXT KEYWORDS would be the
> easy solution.
> 
> On Fri, Aug 23, 2019 at 3:20 AM Arnaud de Montard via 4D_Tech <
> 4d_tech@lists.4d.com> wrote:
> 
>> 
>>> Le 23 août 2019 à 06:52, Kirk Brooks via 4D_Tech <4d_tech@lists.4d.com>
>> a écrit :
>>> 
>>> And as I think about it you need to deal with the multiple match issue
>>> better:
>> 
>> Hi Kirk,
>> still not well awake and too lazy understand if your algorithm was based
>> on chars or words. If it's the former, I'd suggest the use of GET TEXT
>> KEYWORDS to produce 2 arrays of words to compare. In the resulting array
>> words keep ordered as in the text, it may help if the wanted match is the
>> sequence of words.

**
4D Internet Users Group (4D iNUG)
Archive:  http://lists.4d.com/archives.html
Options: https://lists.4d.com/mailman/options/4d_tech
Unsub:  mailto:4d_tech-unsubscr...@lists.4d.com
**

Re: Regex expert needed??

2019-08-23 Thread Kirk Brooks via 4D_Tech
Arnaud,
Good point. If collections aren't available GET TEXT KEYWORDS would be the
easy solution.

On Fri, Aug 23, 2019 at 3:20 AM Arnaud de Montard via 4D_Tech <
4d_tech@lists.4d.com> wrote:

>
> > Le 23 août 2019 à 06:52, Kirk Brooks via 4D_Tech <4d_tech@lists.4d.com>
> a écrit :
> >
> > And as I think about it you need to deal with the multiple match issue
> > better:
>
> Hi Kirk,
> still not well awake and too lazy understand if your algorithm was based
> on chars or words. If it's the former, I'd suggest the use of GET TEXT
> KEYWORDS to produce 2 arrays of words to compare. In the resulting array
> words keep ordered as in the text, it may help if the wanted match is the
> sequence of words.
>
> --
> Arnaud de Montard
>
>
>
> **
> 4D Internet Users Group (4D iNUG)
> Archive:  http://lists.4d.com/archives.html
> Options: https://lists.4d.com/mailman/options/4d_tech
> Unsub:  mailto:4d_tech-unsubscr...@lists.4d.com
> **



-- 
Kirk Brooks
San Francisco, CA
===

What can be said, can be said clearly,
and what you can’t say, you should shut up about

*Wittgenstein and the Computer *
**
4D Internet Users Group (4D iNUG)
Archive:  http://lists.4d.com/archives.html
Options: https://lists.4d.com/mailman/options/4d_tech
Unsub:  mailto:4d_tech-unsubscr...@lists.4d.com
**

Re: Regex expert needed??

2019-08-23 Thread Keisuke Miyako via 4D_Tech
for reference:

simple diff tool for 4D

https://github.com/miyako/4d-plugin-diff-match-patch




**
4D Internet Users Group (4D iNUG)
Archive:  http://lists.4d.com/archives.html
Options: https://lists.4d.com/mailman/options/4d_tech
Unsub:  mailto:4d_tech-unsubscr...@lists.4d.com
**

Re: Regex expert needed??

2019-08-23 Thread Arnaud de Montard via 4D_Tech

> Le 23 août 2019 à 06:52, Kirk Brooks via 4D_Tech <4d_tech@lists.4d.com> a 
> écrit :
> 
> And as I think about it you need to deal with the multiple match issue
> better:

Hi Kirk, 
still not well awake and too lazy understand if your algorithm was based on 
chars or words. If it's the former, I'd suggest the use of GET TEXT KEYWORDS to 
produce 2 arrays of words to compare. In the resulting array words keep ordered 
as in the text, it may help if the wanted match is the sequence of words. 

-- 
Arnaud de Montard 



**
4D Internet Users Group (4D iNUG)
Archive:  http://lists.4d.com/archives.html
Options: https://lists.4d.com/mailman/options/4d_tech
Unsub:  mailto:4d_tech-unsubscr...@lists.4d.com
**

Re: Regex expert needed??

2019-08-22 Thread Kirk Brooks via 4D_Tech
And as I think about it you need to deal with the multiple match issue
better:

$bestMatch:=""

$bestMatch_n_words:=0


Then you loop through the shorter array:

$start:=1  //  first search is on the first word of 

For($i;1;size of array())

$pos1:=Find in array(;{$i}; $start)

while($pos1>0)   // this word matches

$start:=$pos1+1  //  the next Find in array for this word starts on the
next word

$thisMatch:={$i} // a string of matches

$n_words:=1

// now you need to loop through the remaining words in 
until you stop matching

$j:=$i+1 //the word in  to check next

$k:=$pos1+1 // the word in  that must match 

// we need to make sure we don't overrun the size of either array

if ( $j< size of array()) & ( $k< size of array())

while ({$k} = {$j})

$thisMatch:=$thisMatch+" "+{$j}

$n_words:=$n_words+1

end while


if($n_words>$bestMatch_n_words)

$bestMatch_n_words:=$n_words

$bestMatch:=$thisMatch

end if

end if

end while

$start:=1  //  moving on to next word of 

End for

I probably should have actually coded this...

On Thu, Aug 22, 2019 at 9:42 PM Kirk Brooks  wrote:

> Damn, hit send too soon.
> I think you split the two strings into arrays.
> You create:
>
> $bestMatch:=""
>
> $bestMatch_n_words:=0
>
> Then you loop through the shorter array:
>
> For($i;1;size of array())
>
> $pos1:=Find in array(;{$i})
>
> if($pos1>-1) // this word matches
>
> $thisMatch:={$i} // a string of matches
>
> $n_words:=1
>
> // now you need to loop through the remaining words in 
> until you stop matching
>
> $j:=$i+1 //the word in  to check next
>
> $k:=$pos1+1 // the word in  that must match 
>
> while ({$k} = {$j}) & ( $j< size of
> array())
>
> $thisMatch:=$thisMatch+" "+{$j}
>
> $n_words:=$n_words+1
>
> end while
>
>
> if($n_words>$bestMatch_n_words)
>
> $bestMatch_n_words:=$n_words
>
> $bestMatch:=$thisMatch
>
> end if
>
> end if
>
> End for
>
> Use Split string if you can use collections and it should be pretty darn
> fast. Also need to decide what to do with matches of equal length.
>
> On Thu, Aug 22, 2019 at 9:35 PM Kirk Brooks  wrote:
>
>> Chip,
>> I think you split the two strings into arrays.
>> You create two more arrays: $aMatches,  and $aNumWords (unless by
>> 'length' you mean number of characters)
>>
>> The you look through the shorter array:
>>
>> For($i;1;size of array()
>>
>> $pos1:=Find in array(;${$i})
>>
>> if($pos1>-1) // this word matches
>>
>> $thisMatch:={$i} // a string of matches
>>
>> $n_words:=1
>>
>> // now you need to loop through the remaining words in 
>> until you stop matching
>>
>> $j:=$i+1 //the word in  to check next
>>
>> $k:=$pos1+1 // the word in  that must match 
>>
>> while ({$k} = {$j}) & ( $j< size of
>> array())
>>
>> $thisMatch:=$thisMatch+" "+{$j}
>>
>> $n_words:=$n_words+1
>>
>> end while
>>
>>
>> end if
>>
>> End for
>>
>>
>> On Thu, Aug 22, 2019 at 1:13 PM Chip Scheide via 4D_Tech <
>> 4d_tech@lists.4d.com> wrote:
>>
>>> Given 2 strings,
>>> I want to find, and return, the longest substring which is the same in
>>> both, regardless where in either string the longest substring starts.
>>>
>>> ex:
>>> 1- This is my dog
>>> 2- My dog does not have fleas
>>> longest common string is 'my dog'
>>>
>>> how to go about this, efficiently?
>>> I am assuming that there is regex black magic that would do this.
>>>
>>> ---
>>> Gas is for washing parts
>>> Alcohol is for drinkin'
>>> Nitromethane is for racing
>>> **
>>> 4D Internet Users Group (4D iNUG)
>>> Archive:  http://lists.4d.com/archives.html
>>> Options: https://lists.4d.com/mailman/options/4d_tech
>>> Unsub:  mailto:4d_tech-unsubscr...@lists.4d.com
>>> **
>>
>>
>>
>> --
>> Kirk Brooks
>> San Francisco, CA
>> ===
>>
>> What can be said, can be said clearly,
>> and what you can’t say, you should shut up about
>>
>> *Wittgenstein and the Computer *
>>
>>
>
> --
> Kirk Brooks
> San Francisco, CA
> ===
>
> What can be said, can be said clearly,
> and what you can’t say, you should shut up about
>
> *Wittgenstein and the Computer *
>
>

-- 
Kirk Brooks
San Francisco, CA
===

What can be said, can be said clearly,
and what you can’t say, you should shut up about

*Wittgenstein and the Computer *
**
4D Internet Users Group (4D iNUG)
Archive:  http://lists.4d.com/archives.html
Options: https://lists.4d.com/mailman/options/4d_tech
Unsub:  mailto:4d_tech-unsubscr...@lists.4d.com
**

Re: Regex expert needed??

2019-08-22 Thread Kirk Brooks via 4D_Tech
Damn, hit send too soon.
I think you split the two strings into arrays.
You create:

$bestMatch:=""

$bestMatch_n_words:=0

Then you loop through the shorter array:

For($i;1;size of array())

$pos1:=Find in array(;{$i})

if($pos1>-1) // this word matches

$thisMatch:={$i} // a string of matches

$n_words:=1

// now you need to loop through the remaining words in 
until you stop matching

$j:=$i+1 //the word in  to check next

$k:=$pos1+1 // the word in  that must match 

while ({$k} = {$j}) & ( $j< size of
array())

$thisMatch:=$thisMatch+" "+{$j}

$n_words:=$n_words+1

end while


if($n_words>$bestMatch_n_words)

$bestMatch_n_words:=$n_words

$bestMatch:=$thisMatch

end if

end if

End for

Use Split string if you can use collections and it should be pretty darn
fast. Also need to decide what to do with matches of equal length.

On Thu, Aug 22, 2019 at 9:35 PM Kirk Brooks  wrote:

> Chip,
> I think you split the two strings into arrays.
> You create two more arrays: $aMatches,  and $aNumWords (unless by 'length'
> you mean number of characters)
>
> The you look through the shorter array:
>
> For($i;1;size of array()
>
> $pos1:=Find in array(;${$i})
>
> if($pos1>-1) // this word matches
>
> $thisMatch:={$i} // a string of matches
>
> $n_words:=1
>
> // now you need to loop through the remaining words in 
> until you stop matching
>
> $j:=$i+1 //the word in  to check next
>
> $k:=$pos1+1 // the word in  that must match 
>
> while ({$k} = {$j}) & ( $j< size of
> array())
>
> $thisMatch:=$thisMatch+" "+{$j}
>
> $n_words:=$n_words+1
>
> end while
>
>
> end if
>
> End for
>
>
> On Thu, Aug 22, 2019 at 1:13 PM Chip Scheide via 4D_Tech <
> 4d_tech@lists.4d.com> wrote:
>
>> Given 2 strings,
>> I want to find, and return, the longest substring which is the same in
>> both, regardless where in either string the longest substring starts.
>>
>> ex:
>> 1- This is my dog
>> 2- My dog does not have fleas
>> longest common string is 'my dog'
>>
>> how to go about this, efficiently?
>> I am assuming that there is regex black magic that would do this.
>>
>> ---
>> Gas is for washing parts
>> Alcohol is for drinkin'
>> Nitromethane is for racing
>> **
>> 4D Internet Users Group (4D iNUG)
>> Archive:  http://lists.4d.com/archives.html
>> Options: https://lists.4d.com/mailman/options/4d_tech
>> Unsub:  mailto:4d_tech-unsubscr...@lists.4d.com
>> **
>
>
>
> --
> Kirk Brooks
> San Francisco, CA
> ===
>
> What can be said, can be said clearly,
> and what you can’t say, you should shut up about
>
> *Wittgenstein and the Computer *
>
>

-- 
Kirk Brooks
San Francisco, CA
===

What can be said, can be said clearly,
and what you can’t say, you should shut up about

*Wittgenstein and the Computer *
**
4D Internet Users Group (4D iNUG)
Archive:  http://lists.4d.com/archives.html
Options: https://lists.4d.com/mailman/options/4d_tech
Unsub:  mailto:4d_tech-unsubscr...@lists.4d.com
**

Re: Regex expert needed??

2019-08-22 Thread Kirk Brooks via 4D_Tech
Chip,
I think you split the two strings into arrays.
You create two more arrays: $aMatches,  and $aNumWords (unless by 'length'
you mean number of characters)

The you look through the shorter array:

For($i;1;size of array()

$pos1:=Find in array(;${$i})

if($pos1>-1) // this word matches

$thisMatch:={$i} // a string of matches

$n_words:=1

// now you need to loop through the remaining words in 
until you stop matching

$j:=$i+1 //the word in  to check next

$k:=$pos1+1 // the word in  that must match 

while ({$k} = {$j}) & ( $j< size of
array())

$thisMatch:=$thisMatch+" "+{$j}

$n_words:=$n_words+1

end while


end if

End for


On Thu, Aug 22, 2019 at 1:13 PM Chip Scheide via 4D_Tech <
4d_tech@lists.4d.com> wrote:

> Given 2 strings,
> I want to find, and return, the longest substring which is the same in
> both, regardless where in either string the longest substring starts.
>
> ex:
> 1- This is my dog
> 2- My dog does not have fleas
> longest common string is 'my dog'
>
> how to go about this, efficiently?
> I am assuming that there is regex black magic that would do this.
>
> ---
> Gas is for washing parts
> Alcohol is for drinkin'
> Nitromethane is for racing
> **
> 4D Internet Users Group (4D iNUG)
> Archive:  http://lists.4d.com/archives.html
> Options: https://lists.4d.com/mailman/options/4d_tech
> Unsub:  mailto:4d_tech-unsubscr...@lists.4d.com
> **



-- 
Kirk Brooks
San Francisco, CA
===

What can be said, can be said clearly,
and what you can’t say, you should shut up about

*Wittgenstein and the Computer *
**
4D Internet Users Group (4D iNUG)
Archive:  http://lists.4d.com/archives.html
Options: https://lists.4d.com/mailman/options/4d_tech
Unsub:  mailto:4d_tech-unsubscr...@lists.4d.com
**

Re: Regex expert needed??

2019-08-22 Thread Keisuke Miyako via 4D_Tech
regex is pattern matching. "the longest substring" is as generic as it gets, 
not a pattern at all, so one thing for sure is that this is not a regex problem.



**
4D Internet Users Group (4D iNUG)
Archive:  http://lists.4d.com/archives.html
Options: https://lists.4d.com/mailman/options/4d_tech
Unsub:  mailto:4d_tech-unsubscr...@lists.4d.com
**

Re: Regex expert needed??

2019-08-22 Thread Chip Scheide via 4D_Tech
Thanks
I'll look at it tomorrow

On Thu, 22 Aug 2019 16:14:49 -0500, Matt Wennerlund wrote:
> If it doesn't need to work on full word boundaries, then the code 
> below works.  For the two below, the common match would be " have 
> fleas".  21 lines of 4d code, no regex magic, unfortunately.  A few 
> more lines of code if you needed to ignore starting and ending spaces 
> of found matches.
> 
> $string1:="This is my dog, it may have fleas"
> $string2:="My dog does not have fleas"
> 
> 
> There are probably ways to speed it up.  $maxlengthstring_t should 
> end up with the longest string.
> 
> $maxlengthstring_t:=""
> $string1:="This is my dog, it may have fleas"
> $string2:="My dog does not have fleas"
> $lengthtocheck_i:=Length($string1)
> For ($k;1;Length($string1)) //This is my dog; his is my dog; is is my dog...
> $stringtotest_t:=Substring($string1;$k)
> $lengthtocheck_i:=Length($stringtotest_t)
> For ($startPosition_i;1;Length($stringtotest_t))  //"This is my 
> dog"; "This is my do"; "This is my d"...
> 
> $testsubstring:=Substring($stringtotest_t;$startPosition_i;$lengthtocheck_i)
> $found_i:=Position($testsubstring;$string2)
> If ($found_i>0)
> If (Length($testsubstring)>Length($maxlengthstring_t))
> $maxlengthstring_t:=$testsubstring
> $startPosition_i:=1
> End if
> Else
> $startPosition_i:=1
> End if
> $lengthtocheck_i:=$lengthtocheck_i-1
> End for
> End for
> 
> 
> Matt Wennerlund
> 
> 
> 
> Chip Scheide via 4D_Tech wrote:
>> Given 2 strings,
>> I want to find, and return, the longest substring which is the same in
>> both, regardless where in either string the longest substring starts.
>> 
>> ex:
>> 1- This is my dog
>> 2- My dog does not have fleas
>> longest common string is 'my dog'
>> 
>> how to go about this, efficiently?
>> I am assuming that there is regex black magic that would do this.
>> 
>> ---
>> Gas is for washing parts
>> Alcohol is for drinkin'
>> Nitromethane is for racing
>> **
>> 4D Internet Users Group (4D iNUG)
>> Archive:  http://lists.4d.com/archives.html
>> Options: https://lists.4d.com/mailman/options/4d_tech
>> Unsub:  mailto:4d_tech-unsubscr...@lists.4d.com
>> **
> 
> 
---
Gas is for washing parts
Alcohol is for drinkin'
Nitromethane is for racing 
**
4D Internet Users Group (4D iNUG)
Archive:  http://lists.4d.com/archives.html
Options: https://lists.4d.com/mailman/options/4d_tech
Unsub:  mailto:4d_tech-unsubscr...@lists.4d.com
**

Re: Regex expert needed??

2019-08-22 Thread Matt Wennerlund via 4D_Tech
If it doesn't need to work on full word boundaries, then the code below 
works.  For the two below, the common match would be " have fleas".  21 
lines of 4d code, no regex magic, unfortunately.  A few more lines of 
code if you needed to ignore starting and ending spaces of found matches.


$string1:="This is my dog, it may have fleas"
$string2:="My dog does not have fleas"


There are probably ways to speed it up.  $maxlengthstring_t should end 
up with the longest string.


$maxlengthstring_t:=""
$string1:="This is my dog, it may have fleas"
$string2:="My dog does not have fleas"
$lengthtocheck_i:=Length($string1)
For ($k;1;Length($string1)) //This is my dog; his is my dog; is is my dog...
$stringtotest_t:=Substring($string1;$k)
$lengthtocheck_i:=Length($stringtotest_t)
For ($startPosition_i;1;Length($stringtotest_t))  //"This is my 
dog"; "This is my do"; "This is my d"...

$testsubstring:=Substring($stringtotest_t;$startPosition_i;$lengthtocheck_i)

$found_i:=Position($testsubstring;$string2)
If ($found_i>0)
If (Length($testsubstring)>Length($maxlengthstring_t))
$maxlengthstring_t:=$testsubstring
$startPosition_i:=1
End if
Else
$startPosition_i:=1
End if
$lengthtocheck_i:=$lengthtocheck_i-1
End for
End for


Matt Wennerlund



Chip Scheide via 4D_Tech wrote:

Given 2 strings,
I want to find, and return, the longest substring which is the same in
both, regardless where in either string the longest substring starts.

ex:
1- This is my dog
2- My dog does not have fleas
longest common string is 'my dog'

how to go about this, efficiently?
I am assuming that there is regex black magic that would do this.

---
Gas is for washing parts
Alcohol is for drinkin'
Nitromethane is for racing
**
4D Internet Users Group (4D iNUG)
Archive:  http://lists.4d.com/archives.html
Options: https://lists.4d.com/mailman/options/4d_tech
Unsub:  mailto:4d_tech-unsubscr...@lists.4d.com
**


**
4D Internet Users Group (4D iNUG)
Archive:  http://lists.4d.com/archives.html
Options: https://lists.4d.com/mailman/options/4d_tech
Unsub:  mailto:4d_tech-unsubscr...@lists.4d.com
**

Regex expert needed??

2019-08-22 Thread Chip Scheide via 4D_Tech
Given 2 strings, 
I want to find, and return, the longest substring which is the same in 
both, regardless where in either string the longest substring starts.

ex: 
1- This is my dog
2- My dog does not have fleas
longest common string is 'my dog'

how to go about this, efficiently?
I am assuming that there is regex black magic that would do this.

---
Gas is for washing parts
Alcohol is for drinkin'
Nitromethane is for racing 
**
4D Internet Users Group (4D iNUG)
Archive:  http://lists.4d.com/archives.html
Options: https://lists.4d.com/mailman/options/4d_tech
Unsub:  mailto:4d_tech-unsubscr...@lists.4d.com
**