After a while of trying to create the perfect regular expression that would remove script tags from HTML I came across this super simple regular expression. It goes to show you, sometimes the simplest things work best.
s = Regex.Replace(s, "", "",RegexOptions.Singleline|RegexOptions.IgnoreCase);
This is a simple one and it’s relative to the user’s current location. This is important because you don’t want to hard-code your website’s URL onto the htaccess file. The main reason being because you don’t want to switch the user over to an HTTP connection when they are in a HTTPS connection.
RewriteRule ^([a-zA-Z0-9]+)/$ /$1 [R=301,L]
This is a useful tip for when you want to match a word to another word exactly. For example say I want to match the word ‘digit’ in a MySQL query. In a normal LIKE query the word ‘digitize’ would throw a match. We know these two words are NOT the same thing and therefore should not create a match. This is how we would create a query looking for an exact match of the word ‘digit’.
SELECT * FROM `mytable` WHERE `field` REGEXP '[[:<:]]myword[[:>:]]';
This regular expression matches numbers from 100+.
This regular expression piece will remove the colon from the following
But not from the following
Regular expressions are powerful tools in programming, however they can be frustrating to create and can break your program easily. If something changes in the format of whatever you are trying to match, it won’t return the expected result. With this in mind, I share my version of a regular expression made to match hyperlinks.