StrPosAndLen PROCEDURE (string pText,string pRegex,*long pMinLen,*long pMaxLen)
! (c) 2024 Geoff Robinson Vitessegr at gmail dot com
! 29 October 2024
! released under the MIT License https://opensource.org/license/mit
!
! 1 November 2024 - move check to get start position to be AFTER space substitution
! - note: this code does not cope with ranges when replacing spaces!!
x long,auto
max long,auto
b byte
c string(1),over(b) ! single char over b
stPos long ! start position (return value)
dollarEnded string(size(pRegex)+1)
regex &string
CODE
pMinLen = 0; pMaxLen = 0 ! initialise/clear
if size(pText) = 0 or size(pRegex) = 0 then return 0.
if instring(' ',pText) or instring(' ',pRegex) ! includes space so need to replace spaces if possible
loop b = 255 to 1 by -1
if instring(c,pText) then cycle.
if instring(c,pRegex) then cycle.
if instring(c,'^$.[]|{{}*+?\-') then cycle. ! avoid special regex chars
break
end
end
if b ! if we have a replacement char for space then do replacements
loop x = 1 to size(pText)
if pText[x] = ' ' then pText[x] = c.
end
loop x = 1 to size(pRegex)
if pRegex[x] = ' ' then pRegex[x] = c.
end
end
stPos = strPos(pText, pRegex) ! get start position
if ~stPos then return 0. ! no match
if stPos = size(pText) ! single char match
pMinLen = 1
pMaxLen = 1
return stPos
end
if pRegex[size(pRegex)] = '$' and sub(pRegex,size(pRegex)-1,1) <> '\'
regex &= pRegex
else
dollarEnded = pRegex & '$'
regex &= dollarEnded
end
max = size(pText) - stPos ! max increment size
loop x = 0 to max
if strPos(pText[stPos : stPos+x],regex)
pMaxLen = x + 1
if pMinLen = 0 then pMinLen = pMaxLen.
elsif pMaxLen
break
end
end
return stPos ! return starting position
!----
#Edit1 added '-' in regex chars to avoid "if instring(c,'^$.[]|{{}*+?\-') then cycle."
#Edit2 moved check to get start position to be AFTER space substitution
#Edit3 needed to move code to append $ to regex to be AFTER check start pos
I dont see what c is?
Is c supposed to be char(b) ?
I see the code below looping doing a ptext[ x ] = c and pregex[ x ] = c, but the instrings with c, I just dont see what c would be.
Without giving away my code, thats the wrong approach. You have to analyse the regexs, work out what they are, its complicated stuff.
And all this effort and round robin stuff is all just because the search string is clipped.
Its a make work exercise aka resource burn, plus its a way to phish coders abilities and its a way to keep coders from using some tech which is a very useful and productive tech, but would give some military squeaky sphincters when looking at the whole clarion package, to name just a few ways to look at this.
And then when we look at Ai generating code, authorities including militaries have the perfect deniable backdoors into systems because the coder just cut n pasted the code. Even Ive been guilty of that, but does the $billion Ai market deter me from getting a better way to program out to the masses? No.
Its hard not to be cynical, if I’m honest.
And at that point I see you replying so Im logging off… 