Using regexmatches correctly

Please check the FAQ (https://www.xyplorer.com/faq.php) before posting a question...
Post Reply
MBaas
Posts: 578
Joined: 15 Feb 2016 21:08

Using regexmatches correctly

Post 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 :(
______________________________________________
Happy user ;-)

highend
Posts: 13315
Joined: 06 Feb 2011 00:33
Location: Win Server 2022 @100%

Re: Using regexmatches correctly

Post 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
One of my scripts helped you out? Please donate via Paypal

MBaas
Posts: 578
Joined: 15 Feb 2016 21:08

Re: Using regexmatches correctly

Post 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!
______________________________________________
Happy user ;-)

Post Reply