DonationCoder.com forum
 
Read-only archive. This is a static copy of the DonationCoder.com forum. Reading and searching work as before; logging in, posting and private messages do not.
Archive of 2026-10-21 · About this archive · Main site

Author Topic: DONE: Regex Sorter  (Read 33,160 times)

Shardnax

  • Participant
  • Joined in 2011
  • *
  • Posts: 8
DONE: Regex Sorter
« on: March 16, 2011, 04:40 PM »
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 20, 2011, 01:26 AM by mouser »

timns

  • Veni, vidi, debuggi
  • Supporting Member
  • Joined in 2007
  • **
  • Posts: 1,211
    • Participated in NANY Challenge Four Times
Re: DONE: Regex Sorter
« Reply #1 on: March 16, 2011, 04:57 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.

Shardnax

  • Participant
  • Joined in 2011
  • *
  • Posts: 8
Re: DONE: Regex Sorter
« Reply #2 on: March 16, 2011, 05: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

  • I eat Coding Snacks for breakfast...
  • Global Moderator
  • Joined in 2005
  • *****
  • Posts: 5,297
    • Participated in NANY Challenge Seventeen Times
    • Coding Snacks
    • Superboy Coder
    • Cody Award
    • Volunteers/Staff
    • Gathering Badge
Re: DONE: Regex Sorter
« Reply #3 on: March 16, 2011, 07: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

  • Veni, vidi, debuggi
  • Supporting Member
  • Joined in 2007
  • **
  • Posts: 1,211
    • Participated in NANY Challenge Four Times
Re: DONE: Regex Sorter
« Reply #4 on: March 16, 2011, 07: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, 07:50 PM by timns »

skwire

  • I eat Coding Snacks for breakfast...
  • Global Moderator
  • Joined in 2005
  • *****
  • Posts: 5,297
    • Participated in NANY Challenge Seventeen Times
    • Coding Snacks
    • Superboy Coder
    • Cody Award
    • Volunteers/Staff
    • Gathering Badge
Re: DONE: Regex Sorter
« Reply #5 on: March 16, 2011, 07:53 PM »
Yeah, it's general.  Paste a list, provide a needle regex and sort.

mouser

  • First Author
  • Administrator
  • Joined in 2005
  • *****
  • Posts: 40,931
    • Gathering Badge
    • Plugin Coding Medal
    • Participated in NANY Challenge Seventeen Times
    • Cody Award
    • Coding Snacks
    • Volunteers/Staff
Re: DONE: Regex Sorter
« Reply #6 on: March 16, 2011, 08: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
  • *
  • Posts: 8
Re: DONE: Regex Sorter
« Reply #7 on: March 17, 2011, 01:58 AM »
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,197
Re: DONE: Regex Sorter
« Reply #8 on: March 17, 2011, 02:44 AM »
I would be interested in this, nice idea. Thanks Shardnax, skwire and timns.

skwire

  • I eat Coding Snacks for breakfast...
  • Global Moderator
  • Joined in 2005
  • *****
  • Posts: 5,297
    • Participated in NANY Challenge Seventeen Times
    • Coding Snacks
    • Superboy Coder
    • Cody Award
    • Volunteers/Staff
    • Gathering Badge
Re: DONE: Regex Sorter
« Reply #9 on: March 17, 2011, 03:12 AM »
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.png

2011-03-16_215527.png
« Last Edit: March 17, 2011, 12:12 PM by skwire »

Shardnax

  • Participant
  • Joined in 2011
  • *
  • Posts: 8
Re: DONE: Regex Sorter
« Reply #10 on: March 17, 2011, 04:04 AM »
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
It should be in the same order as on top.
« Last Edit: March 17, 2011, 04:14 AM by Shardnax »

skwire

  • I eat Coding Snacks for breakfast...
  • Global Moderator
  • Joined in 2005
  • *****
  • Posts: 5,297
    • Participated in NANY Challenge Seventeen Times
    • Coding Snacks
    • Superboy Coder
    • Cody Award
    • Volunteers/Staff
    • Gathering Badge
Re: DONE: Regex Sorter
« Reply #11 on: March 17, 2011, 05: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
  • *
  • Posts: 8
Re: DONE: Regex Sorter
« Reply #12 on: March 17, 2011, 03:22 PM »
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, 03:47 PM by Shardnax »

skwire

  • I eat Coding Snacks for breakfast...
  • Global Moderator
  • Joined in 2005
  • *****
  • Posts: 5,297
    • Participated in NANY Challenge Seventeen Times
    • Coding Snacks
    • Superboy Coder
    • Cody Award
    • Volunteers/Staff
    • Gathering Badge
Re: DONE: Regex Sorter
« Reply #13 on: March 18, 2011, 08:27 PM »
Shardnax...do we call this one done?

Shardnax

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

skwire

  • I eat Coding Snacks for breakfast...
  • Global Moderator
  • Joined in 2005
  • *****
  • Posts: 5,297
    • Participated in NANY Challenge Seventeen Times
    • Coding Snacks
    • Superboy Coder
    • Cody Award
    • Volunteers/Staff
    • Gathering Badge
Re: DONE: Regex Sorter
« Reply #15 on: March 20, 2011, 01:06 AM »
Fantastic.  I'm glad to help.

mouser

  • First Author
  • Administrator
  • Joined in 2005
  • *****
  • Posts: 40,931
    • Gathering Badge
    • Plugin Coding Medal
    • Participated in NANY Challenge Seventeen Times
    • Cody Award
    • Coding Snacks
    • Volunteers/Staff
Re: DONE: Regex Sorter
« Reply #16 on: March 30, 2011, 10: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).

Original address: https://www.donationcoder.com/forum/index.php?topic=26084.0