Sort list lexicographically ascending ignoring certain symbols
-
I’m currently creating a large list of words for a project and i cannot sort all of the lines while ignoring a certain symbol (hyphen for this case) as shown in this image.
the lines with hyphens at the start are supposed to be somewhere else in the list, making it in alphabetical order. -
Notepad++ has no “sort ignoring hyphens” or equivalent built-in. Sorry.
However, you can replicate it with a multi-step process:
- Search > Replace: Find what =
^-(.*)$
, Replace With =$1☺
, Search Mode = Regular Expression, Replace All - Edit > Line Operations > Sort Lines Lexicographically Ascending
- Search > Replace: Find what =
^(.*)☺$
, Replace With =-$1
, Search Mode = Regular Expression, Replace All
You could even record that as a macro, then save the macro and even give it a keyboard shortcut when you save it, so you can do that at any point in the future.
- Search > Replace: Find what =
-
One possible way to solve this is using the sort features in the Columns++ plugin.
If you want to try it, you can install that plugin from Plugins Admin. Then, select nothing if you want to sort the whole document; otherwise, select the lines you want to sort. When you select a Sort command in the next step, you’ll be prompted to allow the selection to be converted to a rectangular selection; allow it.
There are two sort options that might help. First, try the easy one: select Sort ascending (locale) from the the Columns++ menu. That might give you what you want.
If it doesn’t, a more controllable option is to select Sort… from the menu. The dialog that follows allows you to specify a regular expression that selects the sort key in each line.
Depending on how well you know regular expressions, the help link above and your knowledge might be enough, or you might need more guidance. Try first, and ask if you need more help.
Alternatively, that same dialog allows you to specify more details about the Locale sort, which might solve your problem without regular expressions even if the default locale sort does not.