Search code examples
sublimetext3sublimetext

Copy data between single quotes


I have the following list:

select 'ABC','A101',1;
select 'PABC\CE','U101',2;
select 'A-BCXY','P01',3;
select 'UABZUE','PU101',4;
select 'WABCPY','IP1',5;
select 'R-YUABC','2U1',6;
select 'PYRABCQWDES','U1',7;
......
......
(900 lines)

I want to copy only first data which is in single quotes:

'ABC'
'PABC\CE'
'A-BCXY'
'UABZUE'
'WABCPY'
'R-YUABC'
'PYRABCQWDES'

I tried with Ctrl+D for select and cursor key to copy but unable to get complete string.

enter image description here


Solution

  • You need to use a regular expression. Sublime Text uses the Boost C++ Library Perl Syntax.

    Open the find panel and make sure Regular Expression is selected and Whole Word is NOT selected. Paste the following regex into the panel and click on Find All. The first single quoted text following the word 'select' on every line will be selected throughout the document, the single quotes will also be selected.

    (?<=select )'([^']*)'
    

    The components of that regex are:

    (?<=select )    A lookbehind to find the text: "select "
    '               Match a single quote (i.e. the beginning quote)
    ([^']*)         Match any number of characters that are NOT a single quote
    '               Match a single quote (i.e. the ending quote)
    

    This variation will do the same thing but without selecting the single quotes.

    (?<=select ')([^']*)(?=')