Skip to content

Tag: regex

Regex for youtube channel URL

how can I validate youtube channel URL using REGEX ? I found this pattern but it doesn’t work properly Can anyone help me ? Answer Your problem is the extra pipe after user/ Here is the corrected regex: The reason this is a problem is because it make (channel|user) optional. A better way to write this r…

Regex get all numbers before colon

I have the folling string: I want to get all numbers before the colon and return an array with them. So for the given string i would get the following: Answer You can use this lookahead based regex in preg_match_all: Code: RegEx Demo

replace multiple spaces in a string with a single space

I have a file with has several spaces among the words at some point. I need to clean the file and replace existing multi-spaced sequences with one space only. I have written the following statement which does not work at all, and it seems I’m making a big mistake. My file is very simple. Here is a part …

Greater than and less than symbol in regular expressions

I am new to regular expressions, and I am just tired by really studying all of the regex charatcer and all. I need to know what is the purpose of greater than symbol in regex for eg: Please tell me the use of greater than symbo and less than symbol in regex. Answer The greater than symbol simply matches the

Warning: preg_replace(): Unknown modifier

I have the following error: Warning: preg_replace(): Unknown modifier ‘]’ in xxx.php on line 38 This is the code on line 38: How can I fix this problem? Answer Why the error occurs In PHP, a regular expression needs to be enclosed within a pair of delimiters. A delimiter can be any non-alphanumeri…