জাভাস্ক্রিপ্ট compile() মেথড রেগুলার এক্সপ্রেশন স্ক্রিপ্ট এক্সিকিউশনের সময় কম্পাইল করার জন্য ব্যবহৃত হয়। এটি জাভাস্ক্রিপ্ট ভার্সন ১.৫-এ ডিপ্রিকেটেড।
উদাহরণ
<!DOCTYPE html> <html> <head> <style> body { font-family: "Segoe UI", Tahoma, Geneva, Verdana, sans-serif; } </style> </head> <body> <h1>compile() মেথড</h1> <p class="sample"> That man won the race and the woman over there came second </p> <h3>compile() এর পর</h3> <p class="result"></p> <button class="Btn">এখানে ক্লিক করুন</button> <h3>উপরের বাটনে ক্লিক করলে regex কম্পাইল করে পরিবর্তন করা হবে</h3> <script> let sampleEle = document.querySelector(".sample"); let result = document.querySelector(".result"); document.querySelector(".Btn").addEventListener("click", () => { var str = sampleEle.innerHTML; var pattern = /man/g; var str2 = str.replace(pattern, "person"); result.innerHTML = str2 + "<br>"; pattern = /(wo)?man/g; pattern.compile(pattern); str2 = str.replace(pattern, "person"); result.innerHTML += str2; }); </script> </body> </html>আউটপুট

“এখানে ক্লিক করুন” বাটনে ক্লিক করলে −
