deleting all characters after a semicolon

10,952

Solution 1

The following worked for me with a regular expression:

In Sublime:

  1. Open the replace panel with CTRL + H
  2. Make sure that regular expressions are enabled. It is the left icon ".*" in the same row as the search field (ALT + R).
  3. Enter in "Find What": ^([^;]*);.*$
  4. Enter in "Replace With": \1
  5. Find and replace all

I tested it on Windows, on Mac you probably have to use the CMD instead of the CTRL key.

Solution 2

An alternative to using regular expressions would be using the multi cursor editor to select all the semicolons, then highlight to end of line, then delete.

Using the exact example in the question, this worked perfectly for me:

  1. Highlight the first ;
  2. Press Ctrl + d a few times to highlight the other instances of it too.
  3. Hold Shift and tap End to highlight to the end of the row.
  4. Press Delete

Done using Sublime 3 on Debian - I'm assuming this'll work elsewhere too?

Regular expressions are wonderful, but overkill in this case where a couple of keyboard shortcuts will do the job nicely.

Share:
10,952
nik
Author by

nik

Updated on August 03, 2022

Comments

  • nik
    nik almost 2 years

    I am using sublime on Mac I have something like this

    Q21162;E5QCE7
    E5QCF5;P91040
    E5QCF6;E5QCF8;P34558
    E5QCG0;Q09499
    E5QCG2
    

    I want to get rid of everything after the first ; so I want the output like this

    Q21162
    E5QCF5
    E5QCF6
    E5QCG0
    E5QCG2