3

I am wondering if we can do the following with notepad++. I have an exhaustive list of all countries in the word, this is small part of it:

Afghanistan : '',
Albania : '',
Algeria : '',
American Samoa : '',
Andorra : '',
Angola : '',
Anguilla : '',
Antigua and Barbuda  : '',

I need to inject each of those countries between the single quotes, like this:

Afghanistan : 'Afghanistan',
Albania : 'Albania',
Algeria : 'Algeria',
American Samoa : 'American Samoa',
Andorra : 'Andorra',
Angola : 'Angola',
Anguilla : 'Anguilla',
Antigua and Barbuda  : 'Antigua and Barbuda',

Is there anyway where we can parse each line and inject the each country as indicated above using some kind or regular expression?

Toto
  • 89,455
  • 62
  • 89
  • 125
Hussein Salman
  • 7,806
  • 15
  • 60
  • 98

2 Answers2

8
  • Ctrl+H
  • Find what: ^(.+?)\h+:\h+'
  • Replace with: $0$1
  • check Wrap around
  • check Regular expression
  • DO NOT CHECK . matches newline
  • Replace all

Explanation:

^           : begining of line
  (.+?)     : group 1, 1 or more any character not greedy
  \h+       : 1 or more horizontal spaces
  :         : literally  colon
  \h+       : 1 or more horizontal spaces
  '         : single quote

Replacement:

$0      : whole match
$1      : content of group 1 (ie the country name)

Result for given example:

Afghanistan : 'Afghanistan',
Albania : 'Albania',
Algeria : 'Algeria',
American Samoa : 'American Samoa',
Andorra : 'Andorra',
Angola : 'Angola',
Anguilla : 'Anguilla',
Antigua and Barbuda  : 'Antigua and Barbuda',    
Toto
  • 89,455
  • 62
  • 89
  • 125
1

You can do that easily in Notepad++ with Regex Search & replace.

  1. Open file in Notepad++
  2. Open Search -> Replace from main menu (or Ctrl+H)
  3. In Find what: line type ^(.*?)\s:\s'',$
  4. In Replace with: line type $1 : '$1',
  5. Check Regular expression radio in Search Mode panel
  6. Click Replace All button.

Below you can see the result I got from your sample data. enter image description here

Wh1T3h4Ck5
  • 8,399
  • 9
  • 59
  • 79