Page 1 of 1

[Scripting] Sort fail

Posted: 12 Jun 2016 03:20
by binocular222

Code: Select all

 $list1 = <<<HEREDOC
x?tag1
a?tag1
b?tag1
x?tag2
a?tag2
b?tag2
HEREDOC;

	foreach ($tag, 'tag1, tag2', ", ") {
		$matches = regexmatches($list1, "^.*\?$tag", "<crlf>");
		$list = regexreplace(regexreplace($matches, "\?.*"),"^.*\\");
		$list = formatlist($list, "s", "<crlf>"); //Sort  => Not work, I don't know why
		text $list;
	}
The cause seems due to foreach

Re: [Scripting] Sort fail

Posted: 12 Jun 2016 07:19
by highend
The cause is your greedy regex...

Code: Select all

regexreplace($matches, "\?.*")
Produces empty matches so that the delimiter is not a <crlf> anymore -> formatlist fails

Use this instead:

Code: Select all

regexreplace($matches, "\?.*?(?=$)")

Re: [Scripting] Sort fail [solved]

Posted: 12 Jun 2016 09:04
by binocular222
Thanks, that works.