Plugin code - RegexMatchAll() bug

Post your questions and problem reports here

Moderator: kfury77

Forum rules
Please try to follow these guidelines. This will help to receive faster and more accurate response.

  • Check the Support section of the corresponding product first. Chances are you will find your answer there;
  • Do not create new topics for already reported problems. Add your comments to the existing topics instead;
  • Create separate topic for each problem request. Do NOT post a number of non-related problem reports in a single topic;
  • Give your topic a meaningful title. Titles such as "A question," "Bug report" and "Help!" provide others no clue what your message is about;
  • Include the version number of the software you are using;
  • This is not an official customer support helpdesk. If you need a prompt and official response, please contact our support team directly instead. It may take a while until you receive a reply in the forum;

Plugin code - RegexMatchAll() bug

Postby pmk65 » Sat Jan 14, 2017 4:18 am

If you run this small plugin code snippet, it should dump out every line of the editor content in the message panel.
But it only show/match lines with content, not empty lines as expected.

Code: Select all
for (var i=0;i<Editor.LineCount;i++) {
   if (RegexMatchAll(Editor.LinesAsDisplayed[i], "^(\\s*)(.*)$", true, match, p) == true) {
      Script.Message(Editor.LinesAsDisplayed[i]);
   }
}
There are 10 types of people in the world: Those who understand binary and those who don't.
User avatar
pmk65
 
Posts: 678
Joined: Sun Dec 20, 2009 9:58 pm
Location: Copenhagen, Denmark

Re: Plugin code - RegexMatchAll() bug

Postby Aivars » Sat Jan 14, 2017 11:03 am

I'm not sure this is a bug. This site produces the same results: http://rubular.com/, but if you change \s* to \s*? it starts finding the empty lines, too. I don't know why, though.
Blumentals Software Programmer
User avatar
Aivars
Blumentals Software Developer
 
Posts: 2452
Joined: Thu Aug 22, 2002 1:40 pm
Location: Latvia

Re: Plugin code - RegexMatchAll() bug

Postby pmk65 » Sat Jan 14, 2017 5:51 pm

In plain Javascript or PHP, it matches empty string as expected.

Code: Select all
var a = "";

if (/^(\s*)(.*)$/.test(a)) {
   // Successful match
   alert(1)
} else {
   // Match attempt failed
   alert(0)
}


Code: Select all
"^" +        // Assert position at the beginning of the string
"(" +        // Match the regular expression below and capture its match into backreference number 1
   "\\s" +       // Match a single character that is a “whitespace character” (spaces, tabs, and line breaks)
      "*" +        // Between zero and unlimited times, as many times as possible, giving back as needed (greedy)
")" +
"(" +        // Match the regular expression below and capture its match into backreference number 2
   "." +        // Match any single character that is not a line break character
      "*" +        // Between zero and unlimited times, as many times as possible, giving back as needed (greedy)
")" +
"$"          // Assert position at the end of the string (or before the line break at the end of the string, if any)



Changing \s* to \s*? didn't help. Still no match on empty lines.
There are 10 types of people in the world: Those who understand binary and those who don't.
User avatar
pmk65
 
Posts: 678
Joined: Sun Dec 20, 2009 9:58 pm
Location: Copenhagen, Denmark


Return to HTMLPad / Rapid CSS / Rapid PHP / WeBuilder Support

Who is online

Users browsing this forum: No registered users and 5 guests

cron