UNPKG

tsbase

Version:

Base class libraries for TypeScript

71 lines 2.35 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.Regex = void 0; /** * Regular Expressions and Utilities */ var Regex = /** @class */ (function () { function Regex() { } /** * Executes the given RegExp on a string returning the final aggregated value after * running the aggregator across all matches. * @param regex * @param str * @param initialValue * @param aggregator * @returns */ Regex.AggregateMatches = function (regex, str, initialValue, aggregator) { var match; while ((match = regex.exec(str)) !== null) { aggregator(match, initialValue); } return initialValue; }; Regex.NonAlphaNumeric = /[^a-zA-Z0-9 -]/g; Regex.AnyString = /(.*)/; Regex.WhiteSpace = /\s+/g; Regex.XmlTag = /(<.[^(><.)]+>)/g; Regex.CsvData = /(?:,|\n|^)("(?:(?:"")*[^"]*)*"|[^",\n]*|(?:\n|$))/g; /** * Matches: whatever@somewhere.museum | foreignchars@myforeigncharsdomain.nu | me+mysomething@mydomain.com * * Non-Matches: a@b.c | me@.my.com | a@b.comFOREIGNCHAR */ Regex.Email = /^.+@[^\.].*\.[a-z]{2,}$/; /** * Matches: http://regxlib.com/Default.aspx | http://electronics.cnet.com/electronics/0-6342366-8-8994967-1.html * * Non-Matches: www.yahoo.com */ Regex.Uri = /(http|ftp|https):\/\/[\w\-_]+(\.[\w\-_]+)+([\w\-\.,@?^=%&amp;:/~\+#]*[\w\-\@?^=%&amp;/~\+#])?/; /** * Matches: 1234-1234-1234-1234 | 1234 1234 1234 1234 | 1234123412341234 * * Non-Matches: Visa | 1234 | 123-1234-12345 */ Regex.CreditCard = /^(\d{4}[- ]){3}\d{4}|\d{16}$/; /** * Matches: (111) 222-3333 | 1112223333 | 111-222-3333 * * Non-Matches: 11122223333 | 11112223333 | 11122233333 */ Regex.USPhoneNumber = /^\D?(\d{3})\D?\D?(\d{3})\D?(\d{4})$/; /** * Matches: $3,023,123.34 | 9,876,453 | 123456.78 * * Non-Matches: 4,33,234.34 | $1.234 | abc */ Regex.USCurrency = /^\$?([0-9]{1,3},([0-9]{3},)*[0-9]{3}|[0-9]+)(\.[0-9][0-9])?$/; /** * Matches: 14467 | 144679554 | 14467-9554 * * Non-Matches: 14467 955 | 14467- | 1446-9554 */ Regex.USPostalCode = /^[0-9]{5}([- /]?[0-9]{4})?$/; return Regex; }()); exports.Regex = Regex; ; //# sourceMappingURL=Regex.js.map