Skip to content
A simple regex library for V [this is a fixed version of the ShellBear/v-regex that works with recent V 0.1.22 75510e2]
V
Branch: master
Clone or download
Pull request Compare This branch is 5 commits ahead of shellbear:master.
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
.github/workflows
examples
.gitignore
LICENSE
README.md
lib_pcre.v
match_data.v
regex.v

README.md

v-regex

A simple regex library for VLang. It use bindings from the PCRE library.

(NB: you can install this module using v install spytheman.regex, and then use it with import spytheman.regex)

Example

# 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

You can’t perform that action at this time.