Page 1 of 1

Using regexmatches correctly

Posted: 18 Jan 2021 09:05
by MBaas
I have this script:

Code: Select all

   $foo = readfile("blah");
   $cmds = regexmatches($template,"^\h*>(.*)$",<crlf>);
   text "cmds:<crlf>" . $cmds;
The file "blah" has this content:

Code: Select all

&GoTo
  ##1;
  Location from &other pane|#1070;
  &History
    >Hello World!
  -
-->menu
Unfortunately $cmds is empty so I must have done something wrong - but I can't for the life of me find the bug in my code :(

Re: Using regexmatches correctly

Posted: 18 Jan 2021 09:17
by highend
Without looking at the regex itself, you are searching in $template^^

I have no clue what result you would expect from that pattern or do you see any "h" at the beginning of a line?
Why the hell are you escaping a "h" (in a pattern for VB6)? oO

Re: Using regexmatches correctly

Posted: 18 Jan 2021 09:47
by MBaas
  • well, using $template was the required :oops: -moment :wink: The problem is the same when using the correct varname.
  • with my (admittedly humble) knowledge of regex, \h was supposed to match horizontal whitespace. (I am looking for ">" and it can be preceded by any number of blanks, thought this was the best way to achieve that). Again, maybe one for the doc - but if "regular" regex is not supported, then it should be mentioned. It might be too obvious for those with inside-view, but up to this moment I wasn't even aware that VB6 had it's own flavour of regex which does indeed not support \h.
Using \s instead of \h fixed it!