9951 explained code solutions for 126 technologies


php-regexHow to use PHP regex to match tab?


PHP regex can be used to match tab by using the \t character.

Example code

$string = "This\tis\ta\ttab";
$pattern = "/\t/";

if (preg_match($pattern, $string)) {
    echo "Match found!";
}

Output example

Match found!

Code explanation

  • $string: This is the string that will be searched for the tab character.
  • $pattern: This is the regular expression pattern that will be used to search for the tab character.
  • preg_match(): This is the PHP function used to search for a pattern in a string. It takes two parameters, the first being the pattern and the second being the string.

Helpful links

Edit this code on GitHub