Skip to content
Advertisement

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 of periods are being separated into “..

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: add a violation if starts with an underscore (eventually more than

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, XPath,

preg_match bbcode

I currently have bbcode like this [caption=Some text goes here]image.jpg[/caption] 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=’. …

Insert space after semi-colon, unless it’s part of an HTML entity

I’m trying to insert a space after each semi-colon, unless the semi-colon is part of an HTML entity. The examples here are short, but my strings can be quite long, with several semi-colons (or none). I found the following regular expression that does the trick for short strings: However, if the string is somewhat large, the preg_replace above actually crashes

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: Match four or more dots ., the second parameter is the replacement.

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 label.

Advertisement