Update regex to find a match and replace if present

This commit is contained in:
Anshuman Kumar 2022-12-30 09:42:08 +05:30
parent c71bf6ee48
commit f7f2d0beec
1 changed files with 10 additions and 3 deletions

View File

@ -257,8 +257,14 @@ module.exports = function(request, fs) {
return str return str
if(typeof(user_preferences.domain_youtube) != 'undefined') if(typeof(user_preferences.domain_youtube) != 'undefined')
if(user_preferences.domain_youtube) if(user_preferences.domain_youtube){
str = str.replace(youtubeRegex, protocol + user_preferences.domain_youtube) if (youtubeRegex.test(str)){
str = str.replace(youtubeRegex, protocol + user_preferences.domain_youtube)
} else {
youtubeRegex = /(https?:\/\/)([A-z.]+\.)?youtu(be\.com|\.be)(?=.+)/gm;
str = str.replace(youtubeRegex, protocol + user_preferences.domain_youtube)
}
}
if(typeof(user_preferences.domain_twitter) != 'undefined') if(typeof(user_preferences.domain_twitter) != 'undefined')
if(user_preferences.domain_twitter){ if(user_preferences.domain_twitter){
@ -266,7 +272,8 @@ module.exports = function(request, fs) {
str = str.replace(twitterRegex, protocol + user_preferences.domain_twitter) str = str.replace(twitterRegex, protocol + user_preferences.domain_twitter)
} }
else { else {
str = str.replace('https://twitter.com',protocol + user_preferences.domain_twitter) twitterRegex = /(https?:\/\/)(www\.)?twitter\.com(?=.)/gm;
str = str.replace(twitterRegex, protocol + user_preferences.domain_twitter)
} }
} }