Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9007255
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T01:38:21+00:00 2026-06-16T01:38:21+00:00

How could I use the sort-regexp-fields to emulate the sort-numeric-fields. I tried like this:

  • 0

How could I use the sort-regexp-fields to emulate the sort-numeric-fields. I tried like this:

123
345
90
80
1999

M-x sort-regexp-fields

Regexp specifying records to sort: \ ([0-9]+\)

Regexp specifying key within record: \, \#1

But it can’t work.
what I really want to sort is something like this:

foo index: 123
index: 345 boo
…

the question is: I want to sort the lines by the number after the word “index”, but the number is not in the same field, they just have a word “index” before it. what should I do to complete this? anybody can help me?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-16T01:38:22+00:00Added an answer on June 16, 2026 at 1:38 am

    sort-regexp-fields doesn’t do lexicographical compare, and there’s no trivial way to get it to do that. That said, we can use a trick of defining our own command, and using that command to signal to some advice to shoe-horn in a lexicographical compare.

    The following command does what you want, provided you mark the region around the lines you want to compare:

    (defun my-line-sort (begin end)
      (interactive "r")
      (sort-regexp-fields nil "^.*: +\\([0-9]+\\).*$" "\\1" begin end))
    
    (defun compare-buffer-substrings-lexigraphically (b1 b2)
      (< (string-to-number (buffer-substring-no-properties (car b1) (cdr b1)))
         (string-to-number (buffer-substring-no-properties (car b2) (cdr b2)))))
    
    (defadvice sort-subr (before sort-subr-lexical-compare activate)
      "In special case, force predicate to be a lexical compare"
      (when (eq this-command 'my-line-sort)
        (ad-set-arg 5 'compare-buffer-substrings-lexigraphically)))
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I was wondering how I could sort this array, when I use asort right
I found I could use this technique to retain a sort of state within
I could use another pair of eyes. This script does what I want in
I could use a bit of help with this, as i am new to
It seems like you could use a mashup of Relector and a Debugger to
I know I could use PHP to do this, but wanted to find out
I always thought that you could use OR in a LIKE statment to query
So I would know how to sort it if I could use a vector
I could use a little help. I'm trying to sort a queue of structures
I could use a set of eyes (or more) on this code. I'm trying

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.