Search code examples
regexnotepad++

Regular expression to get only the first word from each line


I have a text file

@sp_id      int,    
@sp_name                varchar(120),
@sp_gender              varchar(10),
@sp_date_of_birth       varchar(10),
@sp_address             varchar(120),
@sp_is_active           int, 
@sp_role            int

Here, I want to get only the first word from each line. How can I do this? The spaces between the words may be space or tab etc.


Solution

  • Find What: ^(\S+).*$

    Replace by : \1

    You can simply use this to get the first word.Here we are capturing the first word in a group and replace the while line by the captured group.