• Stars
    star
    150
  • Rank 240,070 (Top 5 %)
  • Language
    JavaScript
  • License
    MIT License
  • Created over 10 years ago
  • Updated about 8 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Find a lot of kinds of common information in a string. CommonRegex port for JavaScript

CommonRegexJS

CommonRegex port for JavaScript

Find a lot of kinds of common information in a string.

Pull requests welcome!

Please note that this is currently English/US specific.

Build Status

Usage

You can use CommonRegexJS normally, using a script tag:

  <script src="commonregex.js"></script>

Or importing it with RequireJS, putting commonregex.js file inside your RequireJS base directory, using like this:

  requirejs(['commonregex'], function(CommonRegex) {
      //Use CommonRegex normally here
  }

Or install via NPM with

  $ npm install commonregex

And use like this:

  import CommonRegex from 'commonregex'; // For ES6 environments

  var CommonRegex = require('commonregex'); // For ES5 environments

API

You can instantiate a CommonRegex object passing a string in the constructor and use the fields of the object to acess the matches and the methods for the matches of other strings (passing the string as parameter), or not pass a string in the constructor and just use the methods.

Possible properties and its equivalent methods:

  • #dates or #getDates([text])
  • #times or #getTimes([text])
  • #phones or #getPhones([text])
  • #links or #getLinks([text])
  • #emails or #getEmails([text])
  • #IPv4 or #getIPv4([text])
  • #IPv6 or #getIPv6([text])
  • #hexColors or #getHexColors([text])
  • #acronyms or #getAcronyms([text])
  • #money or #getMoney([text])
  • #percentages or #getPercentages([text]) (matches percentages between 0.00% and 100.00%)
  • #creditCards or #getCreditCards([text])
  • #addresses or #getAddresses([text])

The regexes used internally are available at CommonRegex.regexes.

Examples

var text = 'John, please get that article on www.linkedin.com to me by 5:00PM\n'
+ 'on Jan 9th 2012. 4:00 would be ideal, actually. If you have any questions,\n'
+ 'you can reach my associate at (012)-345-6789 or [email protected].\n'
+ 'I\'ll be on UK during the whole week on a J.R.R. Tolkien convention.';

var commonRegex = new CommonRegex(text);
console.log(commonRegex.dates);
//logs ["Jan 9th 2012"]
console.log(commonRegex.times);
//logs ["5:00PM", "4:00"]
console.log(commonRegex.phones);
//logs ["(012)-345-6789"]
console.log(commonRegex.links);
//logs ["www.linkedin.com"]
console.log(commonRegex.emails);
//logs ["[email protected]"]
console.log(commonRegex.getAcronyms());
//logs ["UK", "J.R.R."]

Alternatively, you can generate a single CommonRegex instance and use it to parse multiple segments of text.

var commonRegex = new CommonRegex();
console.log(commonRegex.times('When are you free? Do you want to meet up for coffee at 4:00?''));
//logs ["4:00"]
console.log(commonRegex.getMoney('They said the price was US$5,000.90, actually it is US$3,900.5. It\'s $1100.4 less, can you imagine this?'));
//logs ["US$5,000.90", "US$3,900.5", "$1100.4"]
console.log(commonRegex.getPercentages('I\'m 99.9999999% sure that I\'ll get a raise of 5%.'));
//logs ["99.9999999%", "5%"]
console.log(commonRegex.getIPv6('The IPv6 address for localhost is 0:0:0:0:0:0:0:1, or alternatively, ::1.'));
//logs ["0:0:0:0:0:0:0:1", "::1"]

CommonRegex Ports

There are CommonRegex ports for other languages, see here

More Repositories

1

node-api-boilerplate

DDD/Clean Architecture inspired boilerplate for Node web APIs
TypeScript
3,289
star
2

react-laravel

Package for using ReactJS with Laravel
PHP
900
star
3

react-katex

Display math in TeX with KaTeX and ReactJS
JavaScript
410
star
4

structure

A simple schema/attributes library built on top of modern JavaScript
JavaScript
301
star
5

react-redux-ddd

Just an experiment
JavaScript
88
star
6

CommonRegexRuby

Find a lot of kinds of common information in a string. CommonRegex port for Ruby
Ruby
79
star
7

emittr

A Ruby event emitter implementation.
Ruby
71
star
8

i18node

I18n library for Node.js with support for plurals and genders
JavaScript
65
star
9

jsT9

A text-prediction JavaScript tool
JavaScript
64
star
10

WolverineJS

Useful library for server-side logging
JavaScript
39
star
11

react-predict

ReactJS for input with autocomplete based on list of words
JavaScript
36
star
12

php-babel-transpiler

Transform JavaScript with Babel from PHP
PHP
31
star
13

CommonRegexJava

CommonRegex port for Java
Java
20
star
14

isomorphic-alt-boilerplate

Isomorphic app boilerplate with React + Alt
JavaScript
16
star
15

frontend-architecture-jsconf-chile-2023

Frontend architecture - JSConf Chile 2023
TypeScript
16
star
16

react-laravel-example

An example of how to use react-laravel package
PHP
14
star
17

backbone-dispatcher

A Flux dispatcher for using with Backbone
JavaScript
14
star
18

jsAutoSuggest

Autosuggest JavaScript tool using jsT9
JavaScript
11
star
19

jquery-flux-todo

Experiment on creating a jQuery app with Flux architecture
JavaScript
7
star
20

angular-blog-app

Simple blog app for learning Angular
JavaScript
6
star
21

generator-iso-alt

Generator for isomorphic flux apps with React and Alt
JavaScript
6
star
22

Fraction

C++ lib for use of Fractions instead of float type
C++
4
star
23

umd-templates

UMD pattern templates for gulp-umd compliants
JavaScript
4
star
24

ruby_ddd

Just an experiment
Ruby
3
star
25

wingpanel-indicator-services

Vala
3
star
26

flux-tracker

JavaScript
3
star
27

react-unit-testing

An example of how to unit test React components
JavaScript
3
star
28

joi-repro

JavaScript
2
star
29

componentized-angular

JavaScript
2
star
30

drunk-postman

JavaScript
2
star
31

di-brown-bag

JavaScript
2
star
32

quake-log-parser-haskell

Haskell
2
star
33

phactory-laravel

Use Phactory inside Laravel
PHP
2
star
34

front-end-boilerplate

My boilerplate for front-end projects
JavaScript
2
star
35

cordova-hooks

My personal Cordova/Phonegap hooks
JavaScript
2
star
36

isomorphic-experiences

Experiences for isomorphic approaches
PHP
2
star
37

ee

Experimental event emitter
JavaScript
2
star
38

jquery-pluginconfig

A jQuery plugin that help use data attributes for configuration
JavaScript
2
star
39

room-word-sample

Kotlin
1
star
40

fluxmaker

[WIP]
JavaScript
1
star
41

ruby_error_repository_example

Ruby
1
star
42

express-ajax-only

Express middleware for only accept AJAX request for a given URL
JavaScript
1
star
43

MaMoney

Money control app
Ruby
1
star
44

enemyBoxes

jQuery extensions for make a set of checkboxes that can't be checked at the same time.
JavaScript
1
star
45

c_ddd

It's an experience, don't take it seriously
C
1
star
46

java_ddd

This is just an experience for a study group
Java
1
star
47

express-secure-only

Express middleware for only accept secure requests (i.e. HTTPS requests)
JavaScript
1
star
48

reproduce-sequelize-bug

JavaScript
1
star
49

BackboneFluxTests

Tests mixing Backbone and Flux architecture
JavaScript
1
star