Skip to content
This repository has been archived by the owner on Oct 18, 2021. It is now read-only.

Latest commit

 

History

History
92 lines (62 loc) · 2.16 KB

README.md

File metadata and controls

92 lines (62 loc) · 2.16 KB

2021/10/18 - Please use the official pcre module, by v install pcre, then updating your code to do import pcre instead of import spytheman.regex .

The API is the same, but the official one is supported, unlike this module.

v-regex

A simple regex library for VLang. It wraps the venerable PCRE library, so you will need it installed as well.

Prerequisites:

You can install libpcre using your favourite package manager:

Debian: apt-get install libpcre3-dev

Fedora: yum install pcre-devel

Installation

You can install this module using v install spytheman.regex, and then use it with import spytheman.regex .

When there are updates, you can update with v update spytheman.regex .

You can also just run v install spytheman.regex again.

Example

(this can also be found in examples/match_after.v)

import spytheman.regex

fn main() {
  r := regex.new_regex('Match everything after this: (.+)', 0) or {
    println('An error occured!')
    return
  }

  m := r.match_str('Match everything after this: "I <3 VLang!"', 0, 0) or {
    println('No match!')
    return
  }

  // m.get(0) -> Match everything after this: "I <3 VLang!"
  // m.get(1) -> "I <3 VLang!"'
  // m.get(2) -> Error!
  whole_match := m.get(0) or {
    println('We matched nothing...')
    return
  }

  matched_str := m.get(1) or {
    println('We matched nothing...')
    return
  }

  println(whole_match) // Match everything after this: "I <3 VLang!"
  println(matched_str) // "I <3 VLang!"

  r.free()
}
$ v -o example examples/match_after.v
$ ./example
Match everything after this: "I <3 VLang!"
"I <3 VLang!"

Usage

Some examples are available in the examples directory.

Built With

  • PCRE - Perl Compatible Regular Expressions
  • Vlang - Simple, fast, safe, compiled language

License

MIT

Contributors