Skip to content
Advertisement

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 regex is

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

I can’t get preg_match to test if the entire string matches the regex

I’m using this regular expression to test if a username is valid: [A-Za-z0-9 _]{3,12} when I test it for matches in a text editor with the string test’ing, it highlights ‘test’ and ‘ing’, but when I use the following code in PHP: if(!preg_match(‘/[A-Za-z0-9 _]{3,12}/’, $content) where $content is test’ing and it should return FALSE, it still returns true. Is there

Using getlementbyclass name or getlementbytag to scrape data from html content

Here I have taken source code snipper from webpage : http://www.yelp.com/biz/franchino-san-francisco?start=80. I want to scrape date, review, rate for each block on the page. @: http://ideone.com/fork/Yfw2re I am not much familiar with DOM element, I appreciate if someone can correct this Here is the code : Answer you can loop through the class values or tag names like this :

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 of it:

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-alphanumeric, non-backslash, non-whitespace character; /, #, ~ are

Advertisement