topbanner_forum
  *

avatar image

Welcome, Guest. Please login or register.
Did you miss your activation email?

Login with username, password and session length
  • Saturday December 14, 2024, 9:36 am
  • Proudly celebrating 15+ years online.
  • Donate now to become a lifetime supporting member of the site and get a non-expiring license key for all of our programs.
  • donate

Author Topic: DONE: Regex Sorter  (Read 28314 times)

Shardnax

  • Participant
  • Joined in 2011
  • *
  • default avatar
  • Posts: 8
    • View Profile
    • Donate to Member
DONE: Regex Sorter
« on: March 16, 2011, 11:40 AM »
I maintain the master list and help with maintaining the master list of threads on some sites, alphabetizing them is probably the most troublesome thing to do, on with my request:

What I'm looking for is a text editor like notepad, or an external program to alphabetize text files based on the name that is contained in the brackets of a url tag in BBCode.
Thread Title
*url=http://www.examplesite.com/showthread.php?t=thread]Thread Title 2[/url*

If I posted this incorrectly please tell me, and how I can fix it. Many thanks to anyone that decides to pick up this request.
« Last Edit: March 19, 2011, 08:26 PM by mouser »

timns

  • Supporting Member
  • Joined in 2007
  • **
  • Posts: 1,211
    • View Profile
    • Donate to Member
Re: DONE: Regex Sorter
« Reply #1 on: March 16, 2011, 11:57 AM »
Doesn't sound too bad at all - if no-one picks this up by March 28th, I'll do this one.

How I would do this: a bit of Java that reads a file and applies a regex to find the sort criteria in each line.

Say something like the following: ^.*?=thread\](.*?)\[.*?$

Sort on \1

Rewrite

This would actually be very easy to make configurable, possibly quite handy for other uses.

Shardnax

  • Participant
  • Joined in 2011
  • *
  • default avatar
  • Posts: 8
    • View Profile
    • Donate to Member
Re: DONE: Regex Sorter
« Reply #2 on: March 16, 2011, 12:02 PM »
Doesn't sound too bad at all - if no-one picks this up by March 28th, I'll do this one.

How I would do this: a bit of Java that reads a file and applies a regex to find the sort criteria in each line.

Say something like the following: ^.*?=thread\](.*?)\[.*?$

Sort on \1

Rewrite

This would actually be very easy to make configurable, possibly quite handy for other uses.

Feel free to add extra functionality as you want, all I want is the url sorting :P. Thanks for offering so quickly.

skwire

  • Global Moderator
  • Joined in 2005
  • *****
  • Posts: 5,287
    • View Profile
    • Donate to Member
Re: DONE: Regex Sorter
« Reply #3 on: March 16, 2011, 02:05 PM »
I have this pretty much done.  Would you mind providing a list of valid URLs and your expected sorting of them for testing purposes?  If they're sensitive links, feel free to PM the list.

timns

  • Supporting Member
  • Joined in 2007
  • **
  • Posts: 1,211
    • View Profile
    • Donate to Member
Re: DONE: Regex Sorter
« Reply #4 on: March 16, 2011, 02:49 PM »
skwire, is it a general solution? Since I can think of a couple of uses for this sort of sorting. If it's specific to sorting URLs I may still have a crack at it later.
« Last Edit: March 16, 2011, 02:50 PM by timns, Reason: crack a tit -> crack at it »

skwire

  • Global Moderator
  • Joined in 2005
  • *****
  • Posts: 5,287
    • View Profile
    • Donate to Member
Re: DONE: Regex Sorter
« Reply #5 on: March 16, 2011, 02:53 PM »
Yeah, it's general.  Paste a list, provide a needle regex and sort.

mouser

  • First Author
  • Administrator
  • Joined in 2005
  • *****
  • Posts: 40,914
    • View Profile
    • Mouser's Software Zone on DonationCoder.com
    • Read more about this member.
    • Donate to Member
Re: DONE: Regex Sorter
« Reply #6 on: March 16, 2011, 03:57 PM »
When i saw request i had same exact thoughts as timns (clever hobbit!) -- to let people specify how to extract the sort criteria using a regex.  Very smart.  I may steal this idea and put it in my Clipboard Help+Spell sorting options as well.

Shardnax

  • Participant
  • Joined in 2011
  • *
  • default avatar
  • Posts: 8
    • View Profile
    • Donate to Member
Re: DONE: Regex Sorter
« Reply #7 on: March 16, 2011, 08:58 PM »
I have this pretty much done.  Would you mind providing a list of valid URLs and your expected sorting of them for testing purposes?  If they're sensitive links, feel free to PM the list.

Sent, I was off by the time you posted this or I would have responded sooner.

rgdot

  • Supporting Member
  • Joined in 2009
  • **
  • Posts: 2,193
    • View Profile
    • Donate to Member
Re: DONE: Regex Sorter
« Reply #8 on: March 16, 2011, 09:44 PM »
I would be interested in this, nice idea. Thanks Shardnax, skwire and timns.

skwire

  • Global Moderator
  • Joined in 2005
  • *****
  • Posts: 5,287
    • View Profile
    • Donate to Member
Re: DONE: Regex Sorter
« Reply #9 on: March 16, 2011, 10:12 PM »
Give this a shot:  http://skwire.dcmembers.com/apps/snacks/RegExTextSorter.zip

The app is still early so nothing is saved, etc.  The RegEx needle dropdown does have two entries in it, though, to help you out; the first one ought to work for your URLs.  At this point, you can only use one back-reference.

Here are some screenshots:

2011-03-16_215510.pngDONE: Regex Sorter

2011-03-16_215527.pngDONE: Regex Sorter
« Last Edit: March 17, 2011, 07:12 AM by skwire »

Shardnax

  • Participant
  • Joined in 2011
  • *
  • default avatar
  • Posts: 8
    • View Profile
    • Donate to Member
Re: DONE: Regex Sorter
« Reply #10 on: March 16, 2011, 11:04 PM »
The text between the ][ brackets is what's showing up in the match box.

Edit:
Sort wasn't working at first, it is now. It's quite usable as is, the only issue is this http://img193.imageshack.us/img193/3051/image1vr.jpg
DONE: Regex Sorter

It should be in the same order as on top.
« Last Edit: March 16, 2011, 11:14 PM by Shardnax »

skwire

  • Global Moderator
  • Joined in 2005
  • *****
  • Posts: 5,287
    • View Profile
    • Donate to Member
Re: DONE: Regex Sorter
« Reply #11 on: March 17, 2011, 12:08 AM »
It should be in the same order as on top.

The screenshot is correct.  In other words, "Example 2" should come before "Examplel" in an alpha sort.  Please redownload the zip file.  I fixed an issue where any trailing newlines would negate any output.

Shardnax

  • Participant
  • Joined in 2011
  • *
  • default avatar
  • Posts: 8
    • View Profile
    • Donate to Member
Re: DONE: Regex Sorter
« Reply #12 on: March 17, 2011, 10:22 AM »
I feel dumb, I didn't even notice the l there.

Got it downloaded, it sorts the text in the same order as the source.
« Last Edit: March 17, 2011, 10:47 AM by Shardnax »

skwire

  • Global Moderator
  • Joined in 2005
  • *****
  • Posts: 5,287
    • View Profile
    • Donate to Member
Re: DONE: Regex Sorter
« Reply #13 on: March 18, 2011, 03:27 PM »
Shardnax...do we call this one done?

Shardnax

  • Participant
  • Joined in 2011
  • *
  • default avatar
  • Posts: 8
    • View Profile
    • Donate to Member
Re: DONE: Regex Sorter
« Reply #14 on: March 19, 2011, 11:48 AM »
Certainly, thanks again for being willing to make it :D. This is gonna save me a lot of time.
« Last Edit: March 19, 2011, 11:51 AM by Shardnax »

skwire

  • Global Moderator
  • Joined in 2005
  • *****
  • Posts: 5,287
    • View Profile
    • Donate to Member
Re: DONE: Regex Sorter
« Reply #15 on: March 19, 2011, 08:06 PM »
Fantastic.  I'm glad to help.

mouser

  • First Author
  • Administrator
  • Joined in 2005
  • *****
  • Posts: 40,914
    • View Profile
    • Mouser's Software Zone on DonationCoder.com
    • Read more about this member.
    • Donate to Member
Re: DONE: Regex Sorter
« Reply #16 on: March 30, 2011, 05:57 AM »
I have a feature request that would really come in handy for me -- an option to remove duplicates after sorting, but do duplicate checking again only of regex match group.

(i.e. the whole line doesn't have to be the same to be removed, just the regex match part).