[Scripting] Sort fail

Please check the FAQ (https://www.xyplorer.com/faq.php) before posting a question...
Post Reply
binocular222
Posts: 1424
Joined: 04 Nov 2008 05:35
Location: Win11, Win10, 100% Scaling

[Scripting] Sort fail

Post 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
I'm a casual coder using AHK language. All of my xys scripts:
http://www.xyplorer.com/xyfc/viewtopic. ... 243#p82488

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

Re: [Scripting] Sort fail

Post 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, "\?.*?(?=$)")
One of my scripts helped you out? Please donate via Paypal

binocular222
Posts: 1424
Joined: 04 Nov 2008 05:35
Location: Win11, Win10, 100% Scaling

Re: [Scripting] Sort fail [solved]

Post by binocular222 »

Thanks, that works.
I'm a casual coder using AHK language. All of my xys scripts:
http://www.xyplorer.com/xyfc/viewtopic. ... 243#p82488

Post Reply