Regex (matchChunk) help...

Jerry Jensen jerry at jhjensen.com
Fri Jun 15 12:27:00 EDT 2018


Will this do what you want? (untested)

put empty into tExtract
repeat for each line L in bigText
  if char -9 to -1 of L is “skyrider1” then
    if char 1 to 9 of L is “selkirkst” then
      put L & return after tExtract
    end if
  end if
end repeat
if char -1 of tExtract is return then delete char -1 of tExtract

> On Jun 15, 2018, at 8:45 AM, Glen Bojsza via use-livecode <use-livecode at lists.runrev.com> wrote:
> 
> Hello,
> 
> I have a couple of hundred pages of text where I need to extract out a
> different string.
> 
> The ending of each string I need has the same ending    skyrider1
> 
> The beginning of each string is the same   selkirkst
> 
> The middle of each string can be any text.
> 
> The problem is that within each line where a string exists there are
> several strings that have the same beginning selkirkst but none of the have
> the correct ending skyrider1.
> 
> My thoughts are to find ending of the string first and then work backwards
> to the first beginning string.
> 
> I created the following example which is gibberish but should make this
> clearer... this is the string I want to extract from the line given is
> *selkirkst is
> placed in the second **skyrider1*
> 
> 
> 
> Use the *selkirkst* function to check whether a *string* contains a
> specified pattern. If *selkirkst* includes a pair of parentheses, the
> position of the substring matching the part of theregular expression inside
> the parentheses is placed in the variables in the *positionVarsList*. The
> number of the first character in the matching substring is placed in the
> first variable in the positionVarsList, and the number of the last
> *selkirkst is
> placed in the second **skyrider1*. Additional starting and ending
> positions, matching additional parenthetical expressions, are placed in
> additional pairs of variables in thepositionVarsList. If the
> *selkirkst* function
> returns false, the values of the variables in the positionVarsListare not
> changed. The string and regularExpression are always case-sensitive,
> regardless of the setting of the caseSensitive property. (If you need to
> make a case-insensitive comparison, use "(?i)" at the start of the
> regularExpression to make the match case-insensitive.)
> 
> The next line will not have *is placed in the second*  but some other text
> *selkirkst*  ????   *skyrider1*
> 
> I am not sure if this explains it well enough but I believe a regex
> expression could be used (or perhaps a matchChunk) to extract the correct
> string from each line of text.
> 
> Any suggestions?
> 
> thanks,
> 
> Glen
> _______________________________________________
> use-livecode mailing list
> use-livecode at lists.runrev.com
> Please visit this url to subscribe, unsubscribe and manage your subscription preferences:
> http://lists.runrev.com/mailman/listinfo/use-livecode





More information about the use-livecode mailing list