REGEX-COLLECTION
Useful regex patterns and functions to test them.
Currently using 268
tests for 9
functions to ensure accurate results!
:white_check_mark: Supported patterns for:
CSS comments
Email addresses
Full numbers / Integer
Full numbers / Integer (Negative)
Full numbers / Integer (Positive)
Hex color codes
IP addresses
Telephone numbers
:package: Install
npm i regex-collection
:clipboard: Usage
Importing
JavaScript
const search = require ('regex-collection' )
TypeScript
import * as search from 'regex-collection'
Syntax
The syntax is the same for JavaScript and TypeScript
get
Get all occurrences of regex
const text = "Hello World contact@example.com Bye World hello@world.com"
let result = search.getEmailAddress(text)
is
Check if a string matches to a regex
const text = "Hello World contact@example.com Bye World hello@world.com"
let result = search.isEmailAddress(text)
const text = "contact@example.com"
let result = search.isEmailAddress(text)
Variables
Const cssComment
cssComment: RegExp = /\/\*[^*]*\*+([^\/*][^*]*\*+)*\//
Const emailAddress
emailAddress: RegExp = /(?:[a-z0-9!#$%&'*+/=?^_`{|}~-]+(?:\.[a-z0-9!#$%&'*+/=?^_`{|}~-]+)*|"(?:[\x01-\x08\x0b\x0c\x0e-\x1f\x21\x23-\x5b\x5d-\x7f]|\\[\x01-\x09\x0b\x0c\x0e-\x7f])*")@(?:(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?|\[(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?|[a-z0-9-]*[a-z0-9]:(?:[\x01-\x08\x0b\x0c\x0e-\x1f\x21-\x5a\x53-\x7f]|\\[\x01-\x09\x0b\x0c\x0e-\x7f])+)\])/
Const fullNumber
fullNumber: RegExp = /(?<=\s|^|\s\+|\s\-)[+-]?\d+(?=\s|$)/
Const hexColor
hexColor: RegExp = /#([a-f0-9]{6}|[a-f0-9]{3})/
Const ipv4Address
ipv4Address: RegExp = /\b(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\b/
Const negativeFullNumber
negativeFullNumber: RegExp = /(?<=\s|^)\-\d+(?=\s|$)/
Const positiveFullNumber
positiveFullNumber: RegExp = /(?<=\s|^)\+?\d+(?=\s|$)/
Const telephoneNumber
telephoneNumber: RegExp = /[\(\+]?\b[\+]?[(]?[0-9]{3}[)]?[-\s\.]?[0-9]{3}[-\s\.]?[0-9]{4,6}\b/
Functions
Const getCssComment
getCssComment( text: string ) : null | RegExpMatchArray
Parameters
Returns null
|
RegExpMatchArray
Const getEmailAddress
getEmailAddress( text: string ) : null | RegExpMatchArray
Parameters
Returns null
|
RegExpMatchArray
Const getFullNumber
getFullNumber( text: string ) : null | RegExpMatchArray
Parameters
Returns null
|
RegExpMatchArray
Const getHexColor
getHexColor( text: string ) : null | RegExpMatchArray
Parameters
Returns null
|
RegExpMatchArray
Const getIpv4Address
getIpv4Address( text: string ) : null | RegExpMatchArray
Parameters
Returns null
|
RegExpMatchArray
Const getNegativeFullNumber
getNegativeFullNumber( text: string ) : null | RegExpMatchArray
Parameters
Returns null
|
RegExpMatchArray
Const getPositiveFullNumber
getPositiveFullNumber( text: string ) : null | RegExpMatchArray
Parameters
Returns null
|
RegExpMatchArray
Const getTelephoneNumber
getTelephoneNumber( text: string ) : null | RegExpMatchArray
Parameters
Returns null
|
RegExpMatchArray
Const isCssComment
isCssComment( text: string ) : boolean
Parameters
Returns boolean
Const isEmailAddress
isEmailAddress( text: string ) : boolean
Parameters
Returns boolean
Const isFullNumber
isFullNumber( text: string ) : boolean
Parameters
Returns boolean
Const isHexColor
isHexColor( text: string ) : boolean
Parameters
Returns boolean
Const isIpv4Address
isIpv4Address( text: string ) : boolean
Parameters
Returns boolean
Const isNegativeFullNumber
isNegativeFullNumber( text: string ) : boolean
Parameters
Returns boolean
Const isPositiveFullNumber
isPositiveFullNumber( text: string ) : boolean
Parameters
Returns boolean
Const isTelephoneNumber
isTelephoneNumber( text: string ) : boolean
Parameters
Returns boolean
modify
modify( regex: RegExp , flags: string ) : RegExp
Parameters
regex: RegExp
flags: string
Returns RegExp
Legend
Module
Object literal
Variable
Function
Function with type parameter
Index signature
Type alias
Type alias with type parameter
Enumeration
Enumeration member
Property
Method
Interface
Interface with type parameter
Constructor
Property
Method
Index signature
Class
Class with type parameter
Constructor
Property
Method
Accessor
Index signature
Inherited constructor
Inherited property
Inherited method
Inherited accessor
Protected property
Protected method
Protected accessor
Private property
Private method
Private accessor
Static property
Static method
Matches CSS comments