Regex

grupojaque-ngx-commonsGlobals"lib/helpers/regex/regex.helper"

Index

Variables

Functions

Variables

Const RegexEmail

RegexEmail: RegExp‹› = /^\s@+@\s@+.\s@+$/

Defined in lib/helpers/regex/regex.helper.ts:36

Matches a general structure for emails: '...'@'...'.'...'

This won't check for the validity of domain extensions, or forbidden patterns and characters other than not having more than two @ in the email.

// returns ["hey@hey.com", index: 0, input: "hey@hey.com", groups: undefined]
"hey@hey.com".match(RegexEmail)
// returns null
"hey@hey@hey.com".match(RegexEmail)
// returns null
"hey.com".match(RegexEmail)

Const RegexURL

RegexURL: RegExp‹› = /https?:\/\/(www.)?[-a-zA-Z0-9@:%._+~#=]{1,256}.[a-zA-Z0-9()]{1,6}\b([-a-zA-Z0-9()@:%_+.~#?&//=]*)/gi

Defined in lib/helpers/regex/regex.helper.ts:129


Const RegexValidYoutubeId

RegexValidYoutubeId: RegExp‹› = /[A-Za-z0-9_-]{11}$/

Defined in lib/helpers/regex/regex.helper.ts:84

Matches valid YouTube IDs (11-char base64 with '-' instead of '+' and '_' instead of '/')

// returns ["jNQXAC9IVRw", index: 0, input: "jNQXAC9IVRw", groups: undefined]
"jNQXAC9IVRw".match(RegexValidYoutubeId)
// returns ["___________", index: 0, input: "___________", groups: undefined]
"___________".match(RegexValidYoutubeId)
// returns null, length is not 11
"12".match(RegexValidYoutubeId)
// returns null, length is not 11
"01234567890123".match(RegexValidYoutubeId)
// returns null, invalid char
"jNQXAC9IVR+".match(RegexValidYoutubeId)

Const RegexYouTubeURL

RegexYouTubeURL: RegExp‹› = new RegExp( .*(?:youtu.be\\/|v\\/|u\\/\\w\\/|embed\\/|watch\\?v=)(${stripRegex( RegexValidYoutubeId )}).* )

Defined in lib/helpers/regex/regex.helper.ts:122

Will obtian the video ID from common YouTube URL structures

The returned value v will contain:

Common YouTube URL structures include:

  • '...'youtu.be/{VideoID}
  • '...'watch/v=?{VideoID}
  • '...'v/{VideoID}
  • '...'u/''/{VideoID}
// returns [
// "https://www.youtube.com/watch?v=jNQXAC9IVRw",
// "jNQXAC9IVRw",
// index: 0, input: "jNQXAC9IVRw", groups: undefined]
"https://www.youtube.com/watch?v=jNQXAC9IVRw".match(RegexValidYoutubeId)
// returns [
// "https://youtu.be/jNQXAC9IVRw",
// "jNQXAC9IVRw",
// index: 0, input: "jNQXAC9IVRw", groups: undefined]
"https://youtu.be/jNQXAC9IVRw".match(RegexValidYoutubeId)
// returns null, ID is not valid
"https://youtu.be/++-&/(".match(RegexValidYoutubeId)
// returns null, structure is not valid
"https://yt/jNQXAC9IVRw".match(RegexValidYoutubeId)

see RegexValidYoutubeId

Functions

Const RegexPassword

RegexPassword(minLength: number, maxLength?: number): RegExp‹›

Defined in lib/helpers/regex/regex.helper.ts:57

Matches strings with 1 capital letter, 1 number, 1 symbol, and custom length.

When called like RegexPassword() it'll use 8 as default minimum length.

// returns ["Abc123+-", index: 0, input: "Abc123+-", groups: undefined]
"Abc123+-".match(RegexPassword())
// returns null
"Abc123+-".match(RegexPassword(100))
// returns null
"verysecure".match(RegexPassword)

Parameters:

NameTypeDefaultDescription
minLengthnumber8Minimum number of characters for the password
maxLength?number-Maximum number of characters for the password

Returns: RegExp‹›


Const stripRegex

stripRegex(regex: RegExp): string

Defined in lib/helpers/regex/regex.helper.ts:14

Takes a RegExp and returns only the content, without "/" delimiters or flags

// returns "[a-zA-Z]"
stripRegex(/[a-zA-Z]/)
// returns "[a-zA-Z]"
stripRegex(/[a-zA-Z]/igm)

Parameters:

NameTypeDescription
regexRegExpRegular Expresion to extract the content of

Returns: string