Remove common numeric suffixes (eg: 40m, 60%)

Published on Tue Mar 01 2022

Usage: "40%".replace(/\b([\d\.]+)[mkb%](?!\S)/ig, '$1')

Additional matching regexes for
Remove common numeric suffixes (eg: 40m, 60%)

Remove common numeric suffixes (eg: 40m, 60%)

Usage: "40%".replace(/\b([\d\.]+)[mkb%](?!\S)/ig, '$1')

Remove _1 suffix from image filenames

Remove autogenerated file name suffixes from images whilst preserving the extension (e.g. .jpg) These suffixes are usually added when filename already exists in the directory an image is being saved to by an application. Magento is a fine example of a system that does this.

Remove multiple white spaces between words

Remove multiple white spaces between words and replace it with the char of your choosing.

Replace Commas Inside Quotes

Regex to remove commas within quotes. (Common situtaion in .csv files) Eg: data,"some ""embedded"" stuff,commas,inside,quotes",more Replace String would be something like this: \1&\2&\3&\4&\5\&\6&\7&\8&\9 which would replace the commas inside the quotes with '&'s Caveats: * embedded quotes ("") remain in the matches * limit of 9 terms within quotes Work in progress ...

Validate alphanumeric and numeric range

For Validating alphanumeric and numeric range

Website validation

Simple website validation for your casual usage

Shorten file path with /../

Example usage: $Path = preg_replace('/(?:^|(?<=\/))(?:[^\s.\/]+|\.(?!\.\/))++\/\.\.\//i', '', $Path);

Numeric values greater than zero with decimal

Pattern that only accept numeric value and greater than zero with up to decimal places( you can change the decimal places just replace {1,2} depend on how many decimal places you like

url match

match the most common url stuctures

Common log format datetime

Parses the common log format into component elements. According to wikipedia, common log is strftime format %d/%b/%Y:%H:%M:%S %z