List of Special Characters in Regex in PHP

If you escape an ordinary character - nothing bad will happen - it will still represent itself. The exception is digits, they cannot be escaped.

Often there is doubt whether a given character is special. Some go so far as to escape all suspicious characters in a row. However, this is bad practice (clutters the regex with backslashes).

Are special characters: $ ^ . * + ? \ / {} [] () |

Are not special characters: @ : , ' " ; - _ = < > % # ~ ` & !

Задание 1

Given a string:

php<?php
  $str = 'a.a aba aea';
?>

Write a regex that will find the string 'a.a', without capturing the others.

Задание 2

Given a string:

php<?php
  $str = '2+3 223 2223';
?>

Write a regex that will find the string '2+3', without capturing the others.

Задание 3

Given a string:

php<?php
  $str = '23 2+3 2++3 2+++3 345 567';
?>

Write a regex that will find the strings '2+3', '2++3', '2+++3', without capturing the others (+ can be any number).

Задание 4

Given a string:

php<?php
  $str = '23 2+3 2++3 2+++3 445 677';
?>

Write a regex that will find the strings '23', '2+3', '2++3', '2+++3', without capturing the others.

Задание 5

Given a string:

php<?php
  $str = '*+ *q+ *qq+ *qqq+ *qqq qqq+';
?>

Write a regex that will find the strings '*q+', '*qq+', '*qqq+', without capturing the others.

Задание 6

Given a string:

php<?php
  $str = '[abc] {abc} abc (abc) [abc]';
?>

Write a regex that will find the strings inside square brackets and replace them with '!'.