Your dot is matching all characters. Escape it (and the other special characters), like this:
preg_replace('/[^a-zA-Z0-9_ %\[\]\.\(\)%&-]/s', '', $String);
More Related Contents:
- Remove multiple whitespaces
- Find a match pattern of any digit and space with any character in a string and replace with | in PHP [closed]
- Warning: preg_replace(): Unknown modifier
- Replace preg_replace() e modifier with preg_replace_callback
- Remove new lines from string and replace with one empty space
- php regex to match outside of html tags
- How to remove non-alphanumeric characters?
- Convert plain text URLs into HTML hyperlinks in PHP
- How to mimic Stack Overflow Auto-Link Behavior
- Remove control characters from PHP string
- How to split a string by multiple delimiters in PHP?
- Convert string into slug with single-hyphen delimiters only
- Split camelCase word into words with php preg_match (Regular Expression)
- Extract URL from string
- What Delimiter to use for preg_replace in PHP (replace working outside of PHP but not inside)
- How to split a long string without breaking words?
- Regular expressions for a range of unicode points PHP
- Replace only first match using preg_replace [duplicate]
- Unknown modifier ‘/’ error in PHP [duplicate]
- Close open HTML tags in a string
- Regex & PHP – isolate src attribute from img tag
- Remove accents without using iconv
- Replace tabs and spaces with a single space as well as carriage returns and newlines with a single newline
- How to properly escape a backslash to match a literal backslash in single-quoted and double-quoted PHP regex patterns
- Remove all non-numeric characters from a string; [^0-9] doesn’t match as expected
- How to prefix a positive number with plus sign in PHP
- Regex / DOMDocument – match and replace text not in a link
- How to remove numbers from a string with RegEx
- How to validate that a string only contain lowercase letters?
- Regex to match an IP address [closed]