Coder Social home page Coder Social logo

rust-pcre's Introduction

rust-pcre

Rust 1.x+ wrapper for libpcre 8.20+.

Build Status

Quick Start

To use rust-pcre, you can either install libpcre 8.20+ and register with pkg-config or you can let rust-pcre build libpcre from source.

Debian

Debian Squeeze's package for libpcre is for version 8.02 of the library, which is too old. You can either install a newer version of libpcre and register it with pkg-config or just let rust-pcre automatically build libpcre from source.

On Debian Wheezy and newer, install the libpcre3-dev package:

sudo apt-get install libpcre3-dev

Fedora

Install the pcre-devel package.

Mac OS X

Mac OS 10.7 ships with version 8.02 of libpcre. You can either install a newer version of libpcre and register it with pkg-config or just let rust-pcre automatically build libpcre from source.

Homebrew is highly recommended for installing libpcre. With Homebrew, installing the latest versions of Rust and libpcre is as simple as:

brew install rust pcre

To upgrade:

brew update && brew upgrade rust pcre

Ubuntu

The libpcre packages for Ubuntu 10.04 LTS 'Lucid Lynx' and Ubuntu 12.04 LTS 'Precise Pangolin' are too old. You can either install a newer version of libpcre and register it with pkg-config or just let rust-pcre automatically build libpcre from source.

On Ubuntu 12.10 'Quantal Quetzal' and newer, install the libpcre3-dev package:

sudo apt-get install libpcre3-dev

Usage

The basic use of the library involves compiling a pattern regular expression:

let mut re = match Pcre::compile(pattern) {
    Err(err) => {
        // compilation failed
        return;
    },
    Ok(re) => re
};

You can also pass options:

let mut compile_options: EnumSet<CompileOption> = EnumSet::new();
compile_options.insert(CompileOption::Caseless);
let mut re = Pcre::compile_with_options(pattern, &compile_options).unwrap();

To test against a subject string, use one of the exec(), exec_from(), or exec_from_with_options() methods. For example:

let m = match re.exec(subject) {
    None => { println("No match"); return; },
    Some(m) => m
};

See the source of pcredemo for a complete example.

rust-pcre's People

Contributors

cadencemarseille avatar am0d avatar jroweboy avatar artemgr avatar borman avatar killercup avatar azdle avatar

Watchers

James Cloos avatar

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.