mirror of
https://github.com/1c7/Crash-Course-Computer-Science-Chinese.git
synced 2024-12-21 20:30:12 +08:00
26 lines
849 B
JavaScript
26 lines
849 B
JavaScript
// Remove all {}
|
|
// Input: "{\c&HCC9933&}Subtitles by {\c\c&HFFFFFF &}MemoryOnSmells{\c} {\c&HCC9933&}Exclusive for http://UKsubtitles.ru{\c}"
|
|
// Output: "Subtitles by MemoryOnSmells Exclusive for http://UKsubtitles.ru"
|
|
function remove_curly_brace_keep_text(str) {
|
|
return str.replace(/\s*\{.*?\}\s*/g, ' ').trim();
|
|
}
|
|
|
|
function convertHTML(str) {
|
|
var entityPairs = [
|
|
{character: '&', html: '&'},
|
|
{character: '<', html: '<'},
|
|
{character: '>', html: '>'},
|
|
{character: "'", html: '''},
|
|
{character: '"', html: '"'},
|
|
];
|
|
|
|
entityPairs.forEach(function(pair){
|
|
var reg = new RegExp(pair.character, 'g');
|
|
str = str.replace(reg, pair.html);
|
|
});
|
|
return str;
|
|
}
|
|
|
|
exports.remove_curly_brace_keep_text = remove_curly_brace_keep_text
|
|
exports.convertHTML = convertHTML
|