Git Product home page Git Product logo

commonregexruby's Introduction

CommonRegexRuby

Gem Version Build Status

CommonRegex port for Ruby

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

Pull requests welcome!

Please note that this is currently English/US specific.

Installation

To install CommonRegexRuby, just run:

    $ gem install commonregex

Now you're able to use the CommonRegex class, check the API and the examples.

API

Instance methods will return the results relative to the text passed at the constructor. Class methods will receive a text as parameter and return the results relative to it.

Possible instance and class methods:

  • get_dates([text])
  • get_times([text])
  • get_phones([text])
  • get_links([text])
  • get_emails([text])
  • get_ipv4([text])
  • get_ipv6([text])
  • get_hex_colors([text])
  • get_acronyms([text])
  • get_money([text])
  • get_percentages([text]) (matches percentages between 0.00% and 100.00%)
  • get_credit_cards([text])
  • get_addresses([text])

Examples

    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."
    
    common_regex = CommonRegex.new(text)
    put common_regex.get_dates
    // ["Jan 9th 2012"]
    puts common_regex.get_times
    // ["5:00PM", "4:00"]
    puts common_regex.get_phones
    // ["(012)-345-6789"]
    puts common_regex.get_links
    // ["www.linkedin.com"]
    puts common_regex.get_emails
    // ["[email protected]"]
    puts common_regex.get_acronyms
    // ["UK", "J.R.R."]

Alternatively, you can use class methods.

    puts CommonRegex.get_times 'When are you free? Do you want to meet up for coffee at 4:00?'
    // ["4:00"]
    puts CommonRegex.get_money '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?'
    // ["US$5,000.90", "US$3,900.5", "$1100.4"]
    puts CommonRegex.get_percentages 'I\'m 99.9999999% sure that I\'ll get a raise of 5%.'
    // ["99.9999999%", "5%"]
    puts CommonRegex.get_ipv6 'The IPv6 address for localhost is 0:0:0:0:0:0:0:1, or alternatively, ::1.'
    // ["0:0:0:0:0:0:0:1", "::1"]

CommonRegex Ports

There are CommonRegex ports for other languages, see here

commonregexruby's People

Contributors

hidde-jan avatar rscardinho avatar talyssonoc avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

commonregexruby's Issues

error on 2 links without whitespace

thank you for wonderful gem.
come accross this error while scan the .md file:

echo 'at [https://github.com/learnbyexample] (https://github.com/learnbyexample)'|ruby -rcommonregex -wne 'puts CommonRegex.get_links($_)'
https://github.com/learnbyexample
https://github.com/learnbyexample

works fine. The same without whitespace hungs until ^C:

echo 'at [https://github.com/learnbyexample](https://github.com/learnbyexample)'|ruby -rcommonregex -wne 'puts CommonRegex.get_links($_)' 
^C/home/ophil/.gem/ruby/gems/commonregex-0.1.1/lib/commonregex.rb:63:in `scan': Interrupt
	from /home/ophil/.gem/ruby/gems/commonregex-0.1.1/lib/commonregex.rb:63:in `get_matches'
	from /home/ophil/.gem/ruby/gems/commonregex-0.1.1/lib/commonregex.rb:46:in `get_links'
	from -e:1:in `<main>'

ruby -v
ruby 3.0.2p107 (2021-07-07 revision 0db68f0233) [x86_64-linux]

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.