Options
All
  • Public
  • Public/Protected
  • All
Menu

REGEX-COLLECTION

NPM CodeFactor Grade Travis (.org) GitHub package.json version npm npm bundle size

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

Documentation :clipboard:


: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)
// => ["contact@example.com", "hello@world.com"]

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)
// => false
const text = "contact@example.com"

let result = search.isEmailAddress(text)
// => true

Index

Variables

Const cssComment

cssComment: RegExp = /\/\*[^*]*\*+([^\/*][^*]*\*+)*\//

Matches CSS comments

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])+)\])/

Matches email addresses

Const fullNumber

fullNumber: RegExp = /(?<=\s|^|\s\+|\s\-)[+-]?\d+(?=\s|$)/

Matches a full number / integer (1 | 2 | 1337 | +1 | -2 )

Const hexColor

hexColor: RegExp = /#([a-f0-9]{6}|[a-f0-9]{3})/

Matches hex color codes like #fff | #ffffff

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/

Matches IP addresses

Const negativeFullNumber

negativeFullNumber: RegExp = /(?<=\s|^)\-\d+(?=\s|$)/

Matches a positive full number / integer (1 | 2 | +3 | 1337)

Const positiveFullNumber

positiveFullNumber: RegExp = /(?<=\s|^)\+?\d+(?=\s|$)/

Matches a positive full number / integer (1 | 2 | +3 | 1337)

Const telephoneNumber

telephoneNumber: RegExp = /[\(\+]?\b[\+]?[(]?[0-9]{3}[)]?[-\s\.]?[0-9]{3}[-\s\.]?[0-9]{4,6}\b/

Matches on: | (123) 456-7890 | (123)456-7890 | 123-456-7890 | 123.456.7890 | 1234567890 | +31636363634 | 075-63546725

Functions

Const getCssComment

  • getCssComment(text: string): null | RegExpMatchArray
  • Gets all CSS comments from text

    Parameters

    • text: string

      Input text

    Returns null | RegExpMatchArray

Const getEmailAddress

  • getEmailAddress(text: string): null | RegExpMatchArray
  • Gets all email addresses from text

    Parameters

    • text: string

      Input text

    Returns null | RegExpMatchArray

Const getFullNumber

  • getFullNumber(text: string): null | RegExpMatchArray
  • Gets all full numbers from text

    Parameters

    • text: string

      Input text

    Returns null | RegExpMatchArray

Const getHexColor

  • getHexColor(text: string): null | RegExpMatchArray
  • Gets all hex color codes from text

    Parameters

    • text: string

      Input text

    Returns null | RegExpMatchArray

Const getIpv4Address

  • getIpv4Address(text: string): null | RegExpMatchArray
  • Gets all IP addresses from text

    Parameters

    • text: string

      Input text

    Returns null | RegExpMatchArray

Const getNegativeFullNumber

  • getNegativeFullNumber(text: string): null | RegExpMatchArray
  • Gets all positive full numbers from text

    Parameters

    • text: string

      Input text

    Returns null | RegExpMatchArray

Const getPositiveFullNumber

  • getPositiveFullNumber(text: string): null | RegExpMatchArray
  • Gets all positive full numbers from text

    Parameters

    • text: string

      Input text

    Returns null | RegExpMatchArray

Const getTelephoneNumber

  • getTelephoneNumber(text: string): null | RegExpMatchArray
  • Gets all telephone numbers from text

    Parameters

    • text: string

      Input text

    Returns null | RegExpMatchArray

Const isCssComment

  • isCssComment(text: string): boolean
  • Checks if text is an CSS comment

    Parameters

    • text: string

      Input text

    Returns boolean

Const isEmailAddress

  • isEmailAddress(text: string): boolean
  • Checks if text is an email address

    Parameters

    • text: string

      Input text

    Returns boolean

Const isFullNumber

  • isFullNumber(text: string): boolean
  • Checks if text is a full number

    Parameters

    • text: string

      Input text

    Returns boolean

Const isHexColor

  • isHexColor(text: string): boolean
  • Checks if text is a hex color code

    Parameters

    • text: string

      Input text

    Returns boolean

Const isIpv4Address

  • isIpv4Address(text: string): boolean
  • Checks if text is an IP address

    Parameters

    • text: string

      Input text

    Returns boolean

Const isNegativeFullNumber

  • isNegativeFullNumber(text: string): boolean
  • Checks if text is a positive full number

    Parameters

    • text: string

      Input text

    Returns boolean

Const isPositiveFullNumber

  • isPositiveFullNumber(text: string): boolean
  • Checks if text is a positive full number

    Parameters

    • text: string

      Input text

    Returns boolean

Const isTelephoneNumber

  • isTelephoneNumber(text: string): boolean
  • Checks if text is a telephone number.

    Parameters

    • text: string

      Input text

    Returns boolean

modify

  • modify(regex: RegExp, flags: string): RegExp
  • Adds flags to a regex

    Parameters

    • regex: RegExp

      A valid regex (Can be a variable from this module)

    • flags: string

      The flags that will be added to the regex

    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

Generated using TypeDoc