PHP ရှိ Backslash ပြဿနာ

Backslash သည် PHP ၏ special character တစ်ခုဖြစ်သည်။ ဆိုလိုသည်မှာ string အတွင်း၌ backslash ကိုယ်တိုင်ကို ကိုယ်စားပြုစေလိုပါက၊ ကျွန်ုပ်တို့သည် ၎င်းကို နှစ်ဆပွားရေးရမည်-

php<?php
  $str = '\\ \\\\ \\\\\\'; // တကယ်တော့ string သည် '\ \\ \\\' ဖြစ်သည်
?>

Backslash သည် regular expressions ၏ special character လည်းဖြစ်သည်။ ဆိုလိုသည်မှာ regular expression အတွင်း၌၊ backslash ကိုယ်တိုင်ကို ကိုယ်စားပြုစေလိုပါက၊ ၎င်းကို အကြိမ်ပေါင်း လေးကြိမ် ရေးရမည်-

php<?php
  echo preg_replace('#\\\\#', '!', '\\ \\\\ \\\\\\'); // '! ! !!' ကိုထုတ်ပေးမည်
?>

ယခု regular expression တစ်ခုကို ရေးကြည့်ကြပါစို့၊ အရာတွင် ရှာဖွေမည့် pattern သည် ဤသို့ဖြစ်သည်- backslash တစ်ကြိမ် သို့မဟုတ် ထို့ထက်ပိုသောအကြိမ်။ ထိုသို့ဆိုပါက ကျွန်ုပ်တို့သည် + operator ကို ၎င်း၏ရှေ့ရှိ 4 characters များအတွက် grouping မပါဘဲ ရေးရမည်-

php<?php
  echo preg_replace('#\\\\+#', '!', '\\ \\\\ \\\\\\'); // '! ! !' ကိုထုတ်ပေးမည်
?>
Задание 1

String အောက်ပါအတိုင်းပေးထားသည်-

php<?php
  $str = 'a\\b c\\d e\\f';
?>

ဤ string အတွင်း အက္ခရာ၊ backslash၊ အက္ခရာ pattern ဖြင့် substring အားလုံးကို ရှာပါ။

Задание 2

String အောက်ပါအတိုင်းပေးထားသည်-

php<?php
  $str = 'a\\b c\\\\d e\\\\\\f';
?>

ဤ string အတွင်း အက္ခရာ၊ backslash အကြိမ်ရေမည်မျှမဆို၊ အက္ခရာ pattern ဖြင့် substring အားလုံးကို ရှာပါ။