deleting all characters after a semicolon
10,952
Solution 1
The following worked for me with a regular expression:
In Sublime:
- Open the replace panel with CTRL + H
- Make sure that regular expressions are enabled. It is the left icon ".*" in the same row as the search field (ALT + R).
- Enter in "Find What":
^([^;]*);.*$
- Enter in "Replace With":
\1
- 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:
- Highlight the first ;
- Press Ctrl + d a few times to highlight the other instances of it too.
- Hold Shift and tap End to highlight to the end of the row.
- 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.
Author by
nik
Updated on August 03, 2022Comments
-
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