Skip to content

Tag: regex

Optimizing regex for sentence sanitizer

This is a sentence sanitizer. This is the test sentence: hello [[[[[[]]]]]] friend…..? how are you [}}}}}} It should return: hello friend…..? how are you But instead it is returning: hello friend. .. .. ? how are you. So there are 2 problems and I can’t find a solution around them: the set o…

How can i “merge” these two regular expression in PHP?

I’m learning regular expression, so please go easy with me! Username is considered valid when does not start with _ (underscore) and if contains only word characters (letters, digits and underscore itself): In order to merge them in one regular expression, i’ve tried the following: To be read as: …

Get coordinates from script tag, image tag, link

I’m building a search engine for deals and I put all deals on a map, so I need coordinates from websites with scraping. So, coordinates can be on scrit, tag, image, link, etc. Is there any tool or any script, framework, that help me to quick get coordinates from some web sites ? How to do that? With PHP…

preg_match bbcode

I currently have bbcode like this I’d like to use php’s preg_match so I can get the value of the image.jpg, regardless of what’s next to ‘caption=’. …

Replacing x or more dots

I want a clean solution to replace dots in text: Some title…. to this: Some title… Some…. title…… to this: Some… title… How can I replace every sequence of more than 3 dots with 3 dots? Answer With a regular expression based search and replaceDocs: The pattern says: M…

How long can a TLD possibly be?

I’m working on an email validation regex in PHP and I need to know how long the TLD could possibly be and still be valid. I did a few searches but couldn’t find much information on the topic. So how long can a TLD possibly be? Answer DNS allows for a maximum of 63 characters for an individual labe…