最新消息:20210816 当前crifan.com域名已被污染,为防止失联,请关注(页面右下角的)公众号

【已解决】用VSCode中正则处理过滤国家名

VSCode crifan 2425浏览 0评论

想要把:

Lists of cities by country – Wikipedia

中的国家名拷贝出来

先去赋复制:

然后粘贴到VSCode中:

<code>A[edit]

List of cities in Argentina

List of cities in Australia
Afghanistan List of cities in Afghanistan - Islamic Republic of Afghanistan
Albania List of cities in Albania - Republic of Albania
Algeria List of cities in Algeria - People's Democratic Republic of Algeria
Andorra List of cities in Andorra - Principality of Andorra
Angola List of cities in Angola - Republic of Angola
Antigua and Barbuda List of cities in Antigua and Barbuda - Antigua and Barbuda
Argentina List of cities in Argentina - Argentine Republic
Armenia List of cities in Armenia - Republic of Armenia
Aruba List of cities in Aruba - Aruba (Dutch crown dependency)
Australia List of cities in Australia - Commonwealth of Australia
Austria List of cities in Austria - Republic of Austria
Azerbaijan List of cities in Azerbaijan - Republic of Azerbaijan Assam Austria
B[edit]

List of cities in Bahrain

List of cities in Bulgaria
The Bahamas List of cities in the Bahamas - Commonwealth of The Bahamas
Bahrain List of cities in Bahrain - Kingdom of Bahrain
Bangladesh List of cities in Bangladesh - People's Republic of Bangladesh
Barbados List of cities in Barbados - Barbados
Belarus List of cities in Belarus - Republic of Belarus
Belgium List of cities in Belgium - Kingdom of Belgium
Belize List of cities in Belize - Belize
Benin List of cities in Benin - Republic of Benin
Bhutan List of cities in Bhutan - Kingdom of Bhutan
Bolivia List of cities in Bolivia - Plurinational State of Bolivia
Bosnia and Herzegovina List of cities in Bosnia and Herzegovina - Bosnia and Herzegovina
Botswana List of cities in Botswana - Republic of Botswana
Brazil List of cities in Brazil - Federative Republic of Brazil
Brunei List of cities in Brunei - State of Brunei Darussalam
Bulgaria List of cities in Bulgaria - Republic of Bulgaria
Burkina Faso List of cities in Burkina Faso - Burkina Faso
Burundi List of cities in Burundi - Republic of Burundi
C[edit]

List of cities in Chile

List of cities in Cyprus
Cambodia List of cities in Cambodia - Kingdom of Cambodia
Cameroon List of cities in Cameroon - Republic of Cameroon
Canada List of cities in Canada - Canada
Cape Verde List of cities in Cape Verde - Republic of Cape Verde
Cayman Islands List of cities in Cayman Islands - Cayman Islands (UK overseas territory)
Central African Republic List of cities in the Central African Republic - Central African Republic
Chad List of cities in Chad - Republic of Chad
Chile List of cities in Chile - Republic of Chile
China List of cities in China - People's Republic of China
Colombia List of cities in Colombia - Republic of Colombia
Comoros List of cities in Comoros - Union of the Comoros
Democratic Republic of the Congo List of cities in the Democratic Republic of the Congo - Democratic Republic of the Congo
Republic of the Congo List of cities in the Republic of the Congo - Republic of the Congo
Costa Rica List of cities in Costa Rica - Republic of Costa Rica
Ivory Coast List of cities in Côte d'Ivoire - Republic of Côte d'Ivoire
Croatia List of cities in Croatia - Republic of Croatia
Cuba List of cities in Cuba - Republic of Cuba
Cyprus List of cities in Cyprus - Republic of Cyprus
Czech Republic List of cities in the Czech Republic - Czech Republic
D[edit]

List of cities in Denmark
Denmark List of cities in Denmark - Kingdom of Denmark
United Kingdom List of cities in Dhekelia - Sovereign Base Areas of Dhekelia (UK overseas territory)
Djibouti List of cities in Djibouti - Republic of Djibouti
Dominica List of cities in Dominica - Commonwealth of Dominica
Dominican Republic List of cities in the Dominican Republic - Dominican Republic
E[edit]

List of cities in Egypt
East Timor List of cities in East Timor (Timor-Leste) - Democratic Republic of Timor-Leste
Ecuador List of cities in Ecuador - Republic of Ecuador
Egypt List of cities in Egypt - Arab Republic of Egypt
El Salvador List of cities in El Salvador - Republic of El Salvador
Equatorial Guinea List of cities in Equatorial Guinea - Republic of Equatorial Guinea
Eritrea List of cities in Eritrea - State of Eritrea
Estonia List of cities in Estonia - Republic of Estonia
Ethiopia List of cities in Ethiopia - Federal Democratic Republic of Ethiopia
F[edit]

List of cities in Fiji
Falkland Islands List of cities in Falkland Islands - Falkland Islands (British overseas territories)
Faroe Islands List of cities in Faroe Islands - Faroe Islands (Self-governing country in the Kingdom of Denmark)
Fiji List of cities in Fiji - Republic of the Fiji Islands
Finland List of cities in Finland - Republic of Finland
France List of cities in France - French Republic
French Guiana List of cities in French Guiana - French Guiana (French overseas community)
French Polynesia List of cities in French Polynesia - French Polynesia (French overseas community)
G[edit]

List of cities in Gambia

List of cities in Germany
Gabon List of cities in Gabon - Gabonese Republic
The Gambia List of cities in Gambia - Republic of The Gambia
See List of cities in Palestinian Authority areas for Gaza Strip
Georgia (country) List of cities in Georgia - Georgia
Germany List of cities in Germany - Federal Republic of Germany
Ghana List of cities in Ghana - Republic of Ghana
Gibraltar List of cities in Gibraltar - Gibraltar (UK overseas territory)
Greece List of cities in Greece - Hellenic Republic
Greenland List of cities in Greenland - Greenland (Self-governing country in the Kingdom of Denmark)
Grenada List of cities in Grenada - Grenada
Guadeloupe List of cities in Guadeloupe - Guadeloupe (French overseas community)
Guam List of cities in Guam - Territory of Guam (US overseas territory)
Guatemala List of cities in Guatemala - Republic of Guatemala
Guinea List of cities in Guinea - Republic of Guinea
Guinea-Bissau List of cities in Guinea-Bissau - Republic of Guinea-Bissau
Guyana List of cities in Guyana - Co-operative Republic of Guyana
H[edit]

List of cities in Hungary
Haiti List of cities in Haiti - Republic of Haiti
Honduras List of cities in Honduras - Republic of Honduras
Hong Kong List of cities in Hong Kong - Hong Kong Special Administrative Region of the People's Republic of China (Area of special sovereignty)
Hungary List of cities in Hungary - Republic of Hungary
I[edit]

List of cities in Israel
Iceland List of cities in Iceland - Republic of Iceland
India List of cities in India - Republic of India
Indonesia List of cities in Indonesia - Republic of Indonesia
Iran List of cities in Iran - Islamic Republic of Iran
Iraq List of cities in Iraq - Republic of Iraq
Republic of IrelandUnited KingdomList of cities in Ireland - Ireland
See List of cities in the Falkland Islands for Islas Malvinas
Isle of Man List of cities in the Isle of Man - Isle of Man (British Crown dependency)
Israel List of cities in Israel - State of Israel
Italy List of cities in Italy - Italian Republic
J[edit]

List of cities in Japan
Jamaica List of cities in Jamaica - Jamaica
Japan List of cities in Japan - Japan
Jersey List of cities in Jersey - Jersey (British crown dependency)
Jordan List of cities in Jordan - Hashemite Kingdom of Jordan
K[edit]

List of cities in Kuwait
Kazakhstan List of cities in Kazakhstan - Republic of Kazakhstan
Kenya List of cities in Kenya - Republic of Kenya
Kiribati List of cities in Kiribati - Republic of Kiribati
Kuwait List of cities in Kuwait - State of Kuwait
Kyrgyzstan List of cities in Kyrgyzstan - Kyrgyz Republic
Kosovo List of cities in Kosovo - Kosovo Republic
L[edit]
Laos List of cities in Laos - Lao People's Democratic Republic
Latvia List of cities in Latvia - Republic of Latvia
Lebanon List of cities in Lebanon - Republic of Lebanon
Lesotho List of cities in Lesotho - Kingdom of Lesotho
Liberia List of cities in Liberia - Republic of Liberia
Libya List of cities in Libya - Great Socialist People's Libyan Arab Jamahiriya
Liechtenstein List of cities in Liechtenstein - Principality of Liechtenstein
Lithuania List of cities in Lithuania - Republic of Lithuania
Luxembourg List of cities in Luxembourg - Grand Duchy of Luxembourg
M[edit]

List of cities in Malaysia

List of cities in Mexico
Macau List of cities in Macao (Macau) - Macao Special Administrative Region of the People's Republic of China (Area of special sovereignty)
Republic of Macedonia List of cities in Macedonia - Republic of Macedonia
Madagascar List of cities in Madagascar - Republic of Madagascar
Malawi List of cities in Malawi - Republic of Malawi
Malaysia List of cities in Malaysia - Malaysia
Maldives List of cities in Maldives - Republic of Maldives
Mali List of cities in Mali - Republic of Mali
Malta List of cities in Malta - Republic of Malta
Marshall Islands List of cities in the Marshall Islands - Republic of the Marshall Islands
Mauritania List of cities in Mauritania - Islamic Republic of Mauritania
Mauritius List of cities in Mauritius - Republic of Mauritius
Mayotte List of cities in Mayotte - Mayotte (French overseas community)
Mexico List of cities in Mexico - United Mexican States
Federated States of Micronesia List of cities in the Federated States of Micronesia - Federated States of Micronesia
Moldova List of cities in Moldova - Republic of Moldova
Monaco List of cities in Monaco - Principality of Monaco
Mongolia List of cities in Mongolia - Mongolia
Montenegro List of cities in Montenegro - Republic of Montenegro
Montserrat List of cities in Montserrat - Montserrat (UK overseas territory)
Morocco List of cities in Morocco - Kingdom of Morocco
Mozambique List of cities in Mozambique - Republic of Mozambique
Myanmar List of cities in Myanmar - Republic of the Union of Myanmar
N[edit]

List of cities in New Zealand

List of cities in North Korea
Namibia List of cities in Namibia - Republic of Namibia
Nauru List of cities in Nauru - Republic of Nauru
Nepal List of cities in Nepal - Federal Democratic Republic of Nepal
Netherlands List of cities in the Netherlands - Kingdom of the Netherlands
Netherlands Antilles List of cities in the Netherlands Antilles - Netherlands Antilles (Self-governing country in the Kingdom of the Netherlands)
New Caledonia List of cities in New Caledonia - Territory of New Caledonia and Dependencies (French community sui generis)
New Zealand List of cities in New Zealand - New Zealand
Nicaragua List of cities in Nicaragua - Republic of Nicaragua
Niger List of cities in Niger - Republic of Niger
Nigeria List of cities in Nigeria - Federal Republic of Nigeria
Niue List of cities in Niue - Niue (Associated state of New Zealand)
North Korea List of cities in North Korea - Democratic People's Republic of Korea
Northern Cyprus List of cities in Northern Cyprus - Turkish Republic of Northern Cyprus
Northern Mariana Islands List of cities in the Northern Mariana Islands - Commonwealth of the Northern Mariana Islands (US overseas commonwealth)
Norway List of cities in Norway - Kingdom of Norway
O[edit]

List of cities in Oman
Oman List of cities in Oman - Sultanate of Oman
P[edit]
Pakistan List of cities in Pakistan - Islamic Republic of Pakistan

Palau List of cities in Palau - Republic of Palau
Palestinian National Authority List of cities in Palestine- state of palestine
Panama List of cities in Panama - Republic of Panama
Papua New Guinea List of cities in Papua New Guinea - Independent State of Papua New Guinea
Paraguay List of cities in Paraguay - Republic of Paraguay
Peru List of cities in Peru - Republic of Peru
Philippines List of cities in the Philippines - Republic of the Philippines
Pitcairn Islands List of cities in the Pitcairn Islands - Pitcairn, Henderson, Ducie, and Oeno Islands (UK overseas territory)
Poland List of cities in Poland - Republic of Poland
Portugal List of cities in Portugal - Portuguese Republic
Puerto Rico List of cities in Puerto Rico - Commonwealth of Puerto Rico (US overseas commonwealth)
Q[edit]

List of cities in Qatar
Qatar List of cities in Qatar - State of Qatar
R[edit]

List of cities in Russia
Romania List of cities in Romania - Romania
Russia List of cities in Russia - Russian Federation
Rwanda List of cities in Rwanda - Republic of Rwanda
S[edit]

List of cities in South Africa

List of cities in Sweden
Saint Kitts and Nevis List of cities in Saint Kitts and Nevis - Federation of Saint Christopher and Nevis
Saint Lucia List of cities in Saint Lucia - Saint Lucia
Saint Pierre and Miquelon List of cities in Saint-Pierre and Miquelon - Saint Pierre and Miquelon (French overseas community)
Saint Vincent and the Grenadines List of cities in Saint Vincent and the Grenadines - Saint Vincent and the Grenadines
Samoa List of cities in Samoa - Independent State of Samoa
San Marino List of cities in San Marino - Most Serene Republic of San Marino
São Tomé and Príncipe List of cities in São Tomé and Príncipe - Democratic Republic of São Tomé and Príncipe
Saudi Arabia List of cities in Saudi Arabia - Kingdom of Saudi Arabia
Senegal List of cities in Senegal - Republic of Senegal
Serbia List of cities in Serbia - Republic of Serbia
Seychelles List of cities in Seychelles - Republic of Seychelles
Sierra Leone List of cities in Sierra Leone - Republic of Sierra Leone
Singapore List of cities in Singapore - Republic of Singapore
Slovakia List of cities in Slovakia - Slovak Republic
Slovenia List of cities in Slovenia - Republic of Slovenia
Solomon Islands List of cities in the Solomon Islands - Solomon Islands
Somalia List of cities in Somalia - Federal Republic of Somalia
Somaliland List of cities in Somaliland - Republic of Somaliland
South Africa List of cities in South Africa - Republic of South Africa
South Korea List of cities in South Korea (Republic of) - Republic of Korea
South Ossetia List of cities in South Ossetia - Republic of South Ossetia
South Sudan List of cities in South Sudan - Republic of South Sudan
Spain List of cities in Spain - Kingdom of Spain
Sri Lanka List of cities in Sri Lanka - Democratic Socialist Republic of Sri Lanka
Sudan List of cities in Sudan - Republic of the Sudan
Suriname List of cities in Suriname - Republic of Suriname
Svalbard List of cities in Svalbard - Svalbard (Territory of Norway)
Swaziland List of cities in Swaziland - Kingdom of Swaziland
Sweden List of cities in Sweden - Kingdom of Sweden
Switzerland List of cities in Switzerland - Swiss Confederation
Syria List of cities in Syria - Syrian Arab Republic
T[edit]

List of cities in Thailand

List of cities in Turkey
Taiwan List of cities in Taiwan - Republic of China
Tajikistan List of cities in Tajikistan - Republic of Tajikistan
Tanzania List of cities in Tanzania - United Republic of Tanzania
Thailand List of cities in Thailand - Kingdom of Thailand
Togo List of cities in Togo - Togolese Republic
Tokelau List of villages in Tokelau - Tokelau (Territory of New Zealand)
Tonga List of cities in Tonga - Kingdom of Tonga
Transnistria List of cities in Transnistria - Pridnestrovian Moldavian Republic
Trinidad and Tobago List of cities in Trinidad and Tobago - Republic of Trinidad and Tobago
Tunisia List of cities in Tunisia - Tunisian Republic
Turkey List of cities in Turkey - Republic of Turkey
Turkmenistan List of cities in Turkmenistan - Turkmenistan
Turks and Caicos Islands List of cities in the Turks and Caicos Islands - Turks and Caicos Islands (UK overseas territory)
Tuvalu List of cities in Tuvalu - Tuvalu
U[edit]

List of cities in Ukraine

List of cities in the United States

List of cities in the United Kingdom
Uganda List of cities in Uganda - Republic of Uganda
Ukraine List of cities in Ukraine - Ukraine
United Arab Emirates List of cities in the United Arab Emirates - United Arab Emirates
United Kingdom List of cities in the United Kingdom - United Kingdom of Great Britain and Northern Ireland
United States List of cities in the United States - United States of America
Uruguay List of cities in Uruguay - Oriental Republic of Uruguay
Uzbekistan List of cities in Uzbekistan - Republic of Uzbekistan
V[edit]

List of cities in Venezuela
Vanuatu List of cities in Vanuatu - Republic of Vanuatu
Vatican City Vatican City
Venezuela List of cities in Venezuela - Bolivarian Republic of Venezuela
Vietnam List of cities in Vietnam - Socialist Republic of Vietnam
United States Virgin Islands List of cities in the Virgin Islands - United States Virgin Islands (US overseas territory)
W[edit]
See List of cities in Palestinian Authority areas for West Bank
Western Sahara List of cities in Western Sahara - Western Sahara
Y[edit]
Yemen List of cities in Yemen - Republic of Yemen
Z[edit]
Zambia List of cities in Zambia - Republic of Zambia
Zimbabwe List of cities in Zimbabwe - Republic of Zimbabwe
</code>

然后先去想办法,用正则表达式替换,把:

<code>Afghanistan List of cities in Afghanistan - Islamic Republic of Afghanistan
</code>

换成:

<code>Afghanistan
</code>

然后再去写正则,删除掉:

<code>A[edit]
</code>

以及:

<code>List of cities in Argentina
</code>

关于正则的语法,参考:

【已解决】VSCode中如何使用正则表达式去替换且被替换中使用分组group

-》

https://code.visualstudio.com/docs/editor/codebasics

-》

https://github.com/BurntSushi/ripgrep

-〉

https://docs.rs/regex/0.2.5/regex/#syntax

然后用正则可以去匹配绝大多数的内容:

<code>查找规则:^[\w\- ]+.*List of cities in ([\w\- ]+) \s*\- .+$
替换为:$1
</code>

但是个别还是无法替换:

也就懒得继续通过正则变得更复杂去匹配,而用手动处理了。

点击替换,即可:

继续去删除:

<code>A[edit]
</code>

用:

<code>[A-Z]\[edit\]

</code>

 

点击替换:

再去删除:

<code>List of cities in Argentina
</code>

正则:

<code>^List of cities in \w+

</code>

替换效果:

剩下的手动再去整理,得到:

<code>Afghanistan
Albania
Algeria
Andorra
Angola
Antigua and Barbuda
Argentina
Armenia
Aruba
Australia
Austria
Azerbaijan
Bahamas
Bahrain
Bangladesh
Barbados
Belarus
Belgium
Belize
Benin
Bhutan
Bolivia
Bosnia and Herzegovina
Botswana
Brazil
Brunei
Bulgaria
Burkina Faso
Burundi
Cambodia
Cameroon
Canada
Cape Verde
Cayman Islands
Central African Republic
Chad
Chile
China
Colombia
Comoros
Democratic Republic of the Congo
Republic of the Congo
Costa Rica
Côte d'Ivoire
Croatia
Cuba
Cyprus
Czech Republic
Denmark
Dhekelia
Djibouti
Dominica
Dominican Republic
East Timor
Ecuador
Egypt
El Salvador
Equatorial Guinea
Eritrea
Estonia
Ethiopia
Falkland Islands
Faroe Islands
Fiji
Finland
France
French Guiana
French Polynesia
Gabon
Gambia
Gaza Strip
Georgia
Germany
Ghana
Gibraltar
Greece
Greenland
Grenada
Guadeloupe
Guam
Guatemala
Guinea
Guinea-Bissau
Guyana
Haiti
Honduras
Hong Kong
Hungary
Iceland
India
Indonesia
Iran
Iraq
Ireland
Falkland Islands
Isle of Man
Israel
Italy
Jamaica
Japan
Jersey
Jordan
Kazakhstan
Kenya
Kiribati
Kuwait
Kyrgyzstan
Kosovo
Laos
Latvia
Lebanon
Lesotho
Liberia
Libya
Liechtenstein
Lithuania
Luxembourg
Macao
Macedonia
Madagascar
Malawi
Malaysia
Maldives
Mali
Malta
Marshall Islands
Mauritania
Mauritius
Mayotte
Mexico
Federated States of Micronesia
Moldova
Monaco
Mongolia
Montenegro
Montserrat
Morocco
Mozambique
Myanmar
Zealand
Korea
Namibia
Nauru
Nepal
Netherlands
Netherlands Antilles
New Caledonia
New Zealand
Nicaragua
Niger
Nigeria
Niue
North Korea
Northern Cyprus
Northern Mariana Islands
Norway
Oman
Pakistan
Palau
Palestinian
Panama
Papua New Guinea
Paraguay
Peru
the Philippines
the Pitcairn Islands
Poland
Portugal
Puerto Rico
Qatar
Romania
Russia
Rwanda
Africa
Saint Kitts and Nevis
Saint Lucia
Saint-Pierre and Miquelon
Saint Vincent and the Grenadines
Samoa
San Marino
São Tomé and Príncipe
Saudi Arabia
Senegal
Serbia
Seychelles
Sierra Leone
Singapore
Slovakia
Slovenia
the Solomon Islands
Somalia
Somaliland
South Africa
South Korea
South Ossetia
South Sudan
Spain
Sri Lanka
Sudan
Suriname
Svalbard
Swaziland
Sweden
Switzerland
Syria
Taiwan
Tajikistan
Tanzania
Thailand
Togo
Tokelau
Tonga
Transnistria
Trinidad and Tobago
Tunisia
Turkey
Turkmenistan
Turks and Caicos Islands
Tuvalu
United States
United Kingdom
Uganda
Ukraine
United Arab Emirates
United Kingdom
United States
Uruguay
Uzbekistan
Vanuatu
Vatican
Venezuela
Vietnam
Virgin Islands
West Bank
Western Sahara
Yemen
Zambia
Zimbabwe
</code>

243个国家(和地区)

转载请注明:在路上 » 【已解决】用VSCode中正则处理过滤国家名

发表我的评论
取消评论

表情

Hi,您需要填写昵称和邮箱!

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址
82 queries in 0.185 seconds, using 22.11MB memory