Code Monkey home page Code Monkey logo

commonregexscala's Introduction

CommonRegexScala

CommonRegex port for Scala

Find all times, dates, links, phones, and emails in a string.

Pull requests welcome!

Please note that this is currently English/US specific.

Examples and Usage

see also CommonRegexSpec.

scala> import commonregex._
import commonregex._

scala> val text = """John, please get that article
     | on www.linkedin.com or https://google.com or 192.67.23.222
     | to me by 5:00PM on Jan 9th 2012 or 4:00 am on 01/09/12
     | would be ideal, actually. If you have any questions,
     | you can reach my associate at
     | (012)-345-6789 or (230) 241 2422 or [email protected].
     | """.stripMargin

scala> val commonRegex = CommonRegex(text)

// every CommonRegex's method returns Seq.
scala> commonRegex.times            //=> res0: Seq[String] = Stream(5:00PM, ?)
scala> commonRegex.times.toList     //=> res1: List[String] = List(5:00PM, 4:00 am)
scala> commonRegex.dates            //=> res2: Seq[String] = Stream(Jan 9th 2012, ?)
scala> commonRegex.dates.toList     //=> res3: List[String] = List(Jan 9th 2012, 01/09/12)
scala> commonRegex.links            //=> res4: Seq[String] = Stream(www.linkedin.com, ?)
scala> commonRegex.links.toList     //=> res5: List[String] = List(www.linkedin.com, https://google.com)
scala> commonRegex.phones           //=> res6: Seq[String] = Stream((012)-345-6789, ?)
scala> commonRegex.phones.toList    //=> res7: List[String] = List((012)-345-6789, (230) 241 2422)
scala> commonRegex.emails           //=> res8: Seq[String] = Stream([email protected], ?)
scala> commonRegex.emails.toList    //=> res9: List[String] = List([email protected])

CommonRegex also provides scale's Regex object. So, you can use various methods on Regex for example findAllIn.

scala> CommonRegex.time.findAllIn(text).toList      //=> res12: List[String] = List(5:00PM, 4:00 am)
scala> CommonRegex.date.findAllIn(text).toList      //=> res13: List[String] = List(Jan 9th 2012, 01/09/12)
scala> CommonRegex.link.findAllIn(text).toList      //=> res14: List[String] = List(www.linkedin.com, https://google.com)
scala> CommonRegex.phone.findAllIn(text).toList     //=> res15: List[String] = List((012)-345-6789, (230) 241 2422)
scala> CommonRegex.email.findAllIn(text).toList     //=> res16: List[String] = List([email protected])

CommonRegex Ports:

There are some CommonRegex ports for several languages. see [here] (https://github.com/madisonmay/CommonRegex/#commonregex-ports)

commonregexscala's People

Contributors

everpeace avatar

Stargazers

 avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

Forkers

python3pkg

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.