উত্তর:
gবিশ্বব্যাপী ঘোরা, হিসাবে বিশ্বব্যাপী (সমস্ত) প্রতিস্থাপন করুন:
আইআরবি ইন:
>> "hello".sub('l', '*')
=> "he*lo"
>> "hello".gsub('l', '*')
=> "he**o"
replaceএবং replaceAll। তবে রুবির পার্লতে এর শেকড় রয়েছে যা gমডিফায়ার ব্যবহার করে । এটি those জিনিসগুলির মধ্যে একটি মাত্র।
A, sentence, separated, by, commas".gsub!(/(.*),(.*)/,"\\2 \\1") => " commas A, sentence, separated, by" কোনও ধারণা কেন gsub!কেবলমাত্র রেগেক্স গ্রুপগুলি ব্যবহার করার সময় কেবল প্রথম নজিরটিকে সন্ধান / প্রতিস্থাপন করে বলে মনে হচ্ছে?
পার্থক্যটি হ'ল subকেবলমাত্র নির্দিষ্ট প্যাটার্নটির প্রথম ঘটনাকে প্রতিস্থাপন করে, যেখানে gsubএটি সমস্ত উপস্থিতির জন্য হয় (এটি বিশ্বব্যাপী প্রতিস্থাপন করে)।
subএবং gsubযথাক্রমে প্রথম এবং সমস্ত ম্যাচ প্রতিস্থাপন সম্পাদন করুন।
sub(pattern, replacement, x, ignore.case = FALSE, perl = FALSE,
fixed = FALSE, useBytes = FALSE)
gsub(pattern, replacement, x, ignore.case = FALSE, perl = FALSE,
fixed = FALSE, useBytes = FALSE)
sub("4", "8", "An Introduction to R Software Course will be of 4 weeks duration" )
##"An Introduction to R Software Course will be of 8 weeks duration"
gsub("4", "8", "An Introduction to R Software Course will be of 4 weeks duration" )
##"An Introduction to R Software Course will be of 8 weeks duration"