Super Light Regexp engine for C/C++

Overview

SLRE: Super Light Regular Expression library

Documentation and API reference are at docs.cesanta.com/slre

Contributions

To submit contributions, sign Cesanta CLA and send GitHub pull request.

Licensing

SLRE is released under commercial and GNU GPL v.2 open source licenses.

Commercial Projects: Once your project becomes commercialised GPLv2 licensing dictates that you need to either open your source fully or purchase a commercial license. Cesanta offer full, royalty-free commercial licenses without any GPL restrictions. If your needs require a custom license, we’d be happy to work on a solution with you. [Contact us for pricing.] (https://www.cesanta.com/contact)

Issues
  • trouble with terminal quantifier before $

    trouble with terminal quantifier before $

    I want to detect if a Backslash is in my string.... and it fail --- backslash are doubled in my code slre_match("(?i)^.\.$", "c:\Tools", 8, NULL, 0, &msg)

    := edited I'm looking for complete match, that means i should receive 8 and and empty string in msg... msg is sometime filled with "no match" even if it seems to succeed....

    The last chars .$ seems to cause the trouble as slre_match("^.\.", "c:\Tools", 8, NULL, 0, &msg) and slre_match("^(.\.*)$", "c:\Tools", 8, NULL, 0, &msg) return right position value but message is wrong in any case....

    This is not related to backslash ! I also tried with ultra simple expression...... The following fails.... slre_match("a+$", "a", 1, NULL, 0, &msg) slre_match("a*$", "a", 1, NULL, 0, &msg)

    opened by NSP-0123456 8
  • Failure to capture

    Failure to capture

    Add this to the end of the unit_test.c:

      {
        /* Example more complex regular expression */
        static const char * str = "aa 1234 xy\nz";
        static const char * regex = "aa ([0-9]*) *([x-z]*)";
        struct slre_cap caps[2];
        ASSERT(slre_match(regex, str, strlen(str), caps, 2) > 0);
        ASSERT(caps[0].len == 4);
        ASSERT(caps[1].len == 2); /* Fails here */
      }
    

    During " *" evaluation, it does capture correctly the second item, but the end of the loop -look for zero time- overwrite the captured item even if it failed to match.

    opened by X-Ryl669 5
  • Problem with change of licence

    Problem with change of licence

    I was using the previous version of SLRE hosted on googlecode. It had a non-restrictive licence. I found and reported some bugs. They may have been fixed in the Github version but now I can't use SLRE in a closed source application without paying a licence fee. I had put effort into integrating SLRE into one of my applications and in reporting bugs. In the commercial world this might be described as "Bait and switch". I'd be interested in your comments.

    opened by tnay 5
  • trouble with closing quantifier :

    trouble with closing quantifier :

    See following dump :

    if i have .* at the end of an expression the optionnal presence is not taken into account.

    I have compiled slre with SLRE_DEBUG and added a dedicated main.

    ========================> [^.c.$] [abc] doh 0 0 [^.c.$] bar [^.c.$] [abc] bar [^.c.$] [abc] re_len=7 step=1 i=0 j=0 bar [.c.$] [abc] re_len=7 step=1 i=1 j=0 QUANTIFIER: [.] * bar [.] [abc] bar [.] [abc] re_len=1 step=1 i=0 j=0 bar [c._$] [bc] bar [c.*$] [bc] re_len=4 step=1 i=0 j=0 bar [.] [bc] bar [.] [bc] re_len=1 step=1 i=0 j=0 bar [c.*$] [c] bar [c.*$] [c] re_len=4 step=1 i=0 j=0 bar [.] [c] bar [.] [c] re_len=1 step=1 i=0 j=0 bar [c.*$] [] bar [.] [](iter 0) -> 0 [^.c.$] [abc] [No match] Fail on line 681: [slre_match("^.c.$", "abc", 3, NULL, 0, &msg) > 0] ========================> [(?i)^.C.$] [abc] doh 0 0 [^.C.$] bar [^.C.$] [abc] bar [^.C.$] [abc] re_len=7 step=1 i=0 j=0 bar [.C.$] [abc] re_len=7 step=1 i=1 j=0 QUANTIFIER: [.] * bar [.] [abc] bar [.] [abc] re_len=1 step=1 i=0 j=0 bar [C.*$] [bc] bar [C.*$] [bc] re_len=4 step=1 i=0 j=0 bar [.] [bc] bar [.] [bc] re_len=1 step=1 i=0 j=0 bar [C.*$] [c] bar [C.*$] [c] re_len=4 step=1 i=0 j=0 bar [.] [c] bar [.] [c] re_len=1 step=1 i=0 j=0 bar [C.*$] [] bar [.] [](iter 0) -> 0 [^.C.$] [abc] [No match] Fail on line 682: [slre_match("(?i)^._C.*$", "abc", 3, NULL, 0, &msg) > 0]

    opened by NSP-0123456 5
  • Stricter C/C++11 standard compatibility - resolve warnings

    Stricter C/C++11 standard compatibility - resolve warnings

    aim to compile with -Werror

    • [x] cast-equal
    • [ ] assuming signed overflow does not occur when simplifying conditional to constant [-Werror=strict-overflow]
    opened by breznak 3
  • Spaces at the end - but not required

    Spaces at the end - but not required

    Hello,

    is this part of perl regex or it is bug (I am regex newbie)? Look at the spaces at the end in output.

    Input: Heooo Heoa Heoo Heloa Helo Heloo Hello Helloo Regex used: (He(l*)?o[^a])

    Output:

        [Heoo]
        [Heoo]
        [Helo ]
        [Heloo]
        [Hello ]
        [Helloo]
    

    Code used: https://github.com/wordnice/Trnavka/blob/d2e6e03d664366017050a914a929566f4b7fa92b/src/Main.c#L81 (TRN_ is only prefix; Long is long long; REEntry is slre_cap)

    Thanks!

    opened by ghost 3
  • Incorrect work with meta '*'

    Incorrect work with meta '*'

    Matched string "CONTROL" Pattern "^a*CONTROL" (or "^[a]*CONTROL", or "^(a)*CONTROL") It's returning -1 (SLRE_NO_MATCH), but must 0

    Now, I use small hack - "^(a*)?CONTROL"

    opened by BelokrysFedotov 3
  • example problem

    example problem

    Downloaded the code, but the "Example: find all URLs in a string" cannot find any URL in the string. And I noticed that if I make enclosed brackets in regex then it will not work.

    opened by homokia 2
  • NOT a bug: FYI and a usage question about determining capture count

    NOT a bug: FYI and a usage question about determining capture count

    Just wanted to let you know that after a few minutes of tinkering with slre, i bound it to my custom scripting engine:

    api.loadModule('slreish')
    assert 'object' === typename api.slre
    const M = api.slre.match
    const MA = api.slre.matchAll
    const doM = proc(rx,str){
      var m = M(rx, str)
      print('match():', rx, str, ' ==> ', m)
    }
    const doMA = proc(rx,str){
      var m = MA(rx, str)
      print('matchAll():', rx, str, ' ==> ', m)
    }
    
    $doM {([a-z]+)\s+([a-z]+)} "abc def ghi"
    $doMA {([a-z]+)\s+([a-z]+)} "abc def ghi jklmno pq"
    
    // outputs:
    match(): ([a-z]+)\s+([a-z]+) abc def ghi  ==>  ["abc def", "abc", "def"]
    matchAll(): ([a-z]+)\s+([a-z]+) abc def ghi jklmno pq  ==>  [["abc def", "abc", "def"], [" ghi jklmno", "ghi", "jklmno"]]
    

    slre is the only one of the small/embeddable C regex libs i've found/tried which works as advertized!

    One question: the script binding obviously doesn't know how many captures the input string contains, so i just loop over my array size and stop when the first slre_cap.ptr==NULL is found. Is that a usable/reliable heuristic for determining the number of matches dynamically? (Obviously, my slre_cap array size is the upper bound.)

    opened by sgbeal 2
  • invalid match

    invalid match

    slre_match("^(.+)(.)$", "fooh", 4, caps, 10, 0);
    

    caps[0] should be "foo", and caps[1] should be "h". but caps[0] should be "fooh", and caps[1] should be "h".

    opened by mattn 1
  • Flags fix

    Flags fix

    slre.c:169 As far as SLRE_IGNORE_CASE is flag, shouldn't be this

          result = info->flags && SLRE_IGNORE_CASE ?
    

    replaced by

          result = info->flags & SLRE_IGNORE_CASE ? ...
    

    Thanks

    opened by ghost 1
  • Conan package for slre

    Conan package for slre

    Hello, Do you know about Conan? Conan is modern dependency manager for C++. And will be great if your library will be available via package manager for other developers.

    Here you can find example, how you can create package for the library.

    If you have any questions, just ask :-)

    opened by zamazan4ik 0
  • Incorrect processing of closing round bracket

    Incorrect processing of closing round bracket

    Naive example

    Regular expression (foo)(.*(2.)) does not match foo123.

    Explanation

    This is due the incorrect processing of the closing bracket in foo() function:

    /* ... */
    if (re[i] == ')') {
        int ind = info->brackets[info->num_brackets - 1].len == -1 
             ? info->num_brackets - 1 
             : depth;
        info->brackets[ind].len = (int) (&re[i] - info->brackets[ind].ptr);
        depth--;
        FAIL_IF(depth < 0, SLRE_UNBALANCED_BRACKETS);
        FAIL_IF(i > 0 && re[i - 1] == '(', SLRE_NO_MATCH);
    }
    /* ... */
    

    How it is done

    • Last added capturing group is considered:
      • If it is not enclosed, encountered bracket matches opening bracket of this group.
      • Otherwise, encountered bracket matches opening bracket of group with index depth, which is incorrect in general.

    In example shown above, last closing bracket will enclose capturing group with index 1, which is foo, and not capturing group .*(2.). Moreover, this issue can be exploited with a wide range of regular expressions; demonstrated one is merely a proof of concept constructed from one of your unit tests.

    How it shall be done

    Encountered closing bracket shall match last unmatched opening bracket. One shall search for last capturing group, which length is set to -1, and not just assume capturing group with index depth.

    /* ... */
    if (re[i] == ')') {
        int ind = search_for_unmatched_bracket(info);
        info->brackets[ind].len = (int) (&re[i] - info->brackets[ind].ptr);
        depth--;
        FAIL_IF(depth < 0, SLRE_UNBALANCED_BRACKETS);
        FAIL_IF(i > 0 && re[i - 1] == '(', SLRE_NO_MATCH);
    }
    /* ... */
    

    Regards, Arseny.
    opened by aprlv 2
  • memory out of range

    memory out of range

    I want to use slre in my embedded project, but when I use it I am falling into HardFalt interrupt because of memory corruption. I can't show any places, but when I comment all calls to slre_match method. everything is fine.

    This is my example: slre_cap CapturedExp[20]; (slre_match("([ ]*\r)", "diag\r", 5, CapturedExp, 10, SLRE_IGNORE_CASE)

    opened by legier 1
  • Dynamic cap count

    Dynamic cap count

    Well, I want to use SLRE in my project, which consists of just a tiny scripting language and tiny extensions. My goal is to use SLRE to introduce RegEx support to it. The problem is that, in the nature of a scripting language, the user might supply multiple capture groups.

    That is why I want to ask: How can I best count the capture groups in the buffe,r and then perform matching? I could just go through the buffer and look for (s, but maybe there is an easier method?

    opened by IngwiePhoenix 4
  • Support numbered repetition notation by {n}, {min,max}

    Support numbered repetition notation by {n}, {min,max}

    Hi, is it implementation of numbered repetition support by {n} and {min,max} notation planned? It's really a basic standard in regular expressions. Thanks.

    opened by vstk 3
Owner
Cesanta Software
Embedded Communication
Cesanta Software
A small implementation of regular expression matching engine in C

cregex cregex is a compact implementation of regular expression (regex) matching engine in C. Its design was inspired by Rob Pike's regex-code for the

Jim Huang 71 Jul 5, 2022
Easier CPP interface to PCRE regex engine with global match and replace

RegExp Easier CPP interface to PCRE regex engine with global match and replace. I was looking around for better regex engine than regcomp for my C/C++

Yasser Asmi 5 May 21, 2022
Harsh Badwaik 1 Dec 19, 2021
Decoding light morse code with a light dependent resistor and Arduino board

Morse decoder The project's idea is very simple, the Arduino program has the responsibility to upload the sensor's data to the USB serial port.

null 15 Mar 12, 2022
A light-weight Flutter Engine Embedder based on HADK ,which for Android devices that runs without any java code

flutter-hadk A light-weight Flutter Engine Embedder based on HADK ,which for Android devices that runs without any java code 1.Build by android-ndk-to

null 12 Jun 15, 2022
Ducktape is an Open source Light weight 2d Game Engine that gives utmost priority to user convenience.

Ducktape is an Open source Light weight 2d Game Engine that gives utmost priority to user convenience. It is written in c++ and uses SFML and Box2d for graphics and physics respectively.

Ducktape 70 Aug 7, 2022
A toolchain for injecting custom code into Super Mario Galaxy 2.

Syati Syati is a custom code loader for Super Mario Galaxy 2. It is able to compile custom code and link to existing functions in the game to create o

shibbs 20 Mar 29, 2022
Super RDPWrap

SuperRDP English 众所周知,Windows家庭版无法使用远程桌面,RDP Wrapper Library就是用于恢复家庭版该部分阉割的功能。 本项目是基于rdpwrap修改的,在此感谢stascorp的无私的工作。 rdpwrap主要包括安装器和服务dll。 原始版本安装器采用的De

Anhkgg 1.2k Aug 12, 2022
Video, Image and GIF upscale/enlarge(Super-Resolution) and Video frame interpolation. Achieved with Waifu2x, SRMD, RealSR, Anime4K, RIFE, CAIN, DAIN and ACNet.

Video, Image and GIF upscale/enlarge(Super-Resolution) and Video frame interpolation. Achieved with Waifu2x, SRMD, RealSR, Anime4K, RIFE, CAIN, DAIN and ACNet.

Aaron Feng 7.3k Aug 7, 2022
Super ATX Power!

KCORES-CSPS-to-ATX-Converter 项目视频: 1元10瓦 垃圾佬的超级ATX电源-Youtube KCORES 交流群: 826702309 KCORES 官方网站: KCORES.com 从零开始制作: 入门指南 Specification 12V 5V 3.3V 5VSB

KCORES - 氪金核心 348 Aug 12, 2022
gSLICr: Real-time super-pixel segmentation

gSLICr: SLIC superpixels at over 250Hz This is the software bundle "gSLICr", a library for real-time superpixel segmentation written in C++ and CUDA.

Carl Yuheng Ren 302 Jul 10, 2022
> VSS [ Vairous 7x Super Sploit ] v1.0

Coded By V7x Team # Vairous7x SupperSploit [ VSS v1.0 ] Subscribe to Vairous7x on Youtube For Linux: 1- run 'sudo bash vss-setup.sh' 2- run 'sudo bash

Vairous 7x 30 Jul 5, 2021
Super simple code editor designed for students.

HamroCode Super simple code editor designed for students of Nepal. Language Supported JavaScript C C++ QBASIC Downloading Click Here Demo Created & Ma

Hamro Code 5 Mar 30, 2021
Super Mario Remake using C++, SFML, and Image Processing which was a project for Structure Programming Course, 1st Year

Super Mario Remake We use : C++ in OOP concepts SFML for game animations and sound effects. Image processing (Tensorflow and openCV) to add additional

Omar Elshopky 5 Jun 19, 2022
Super Mario World Widescreen is your beloved Mario World SNES game but in the 16:9 resolution.

Super Mario World Widescreen is your beloved Mario World SNES game but in the 16:9 resolution. This is possible by expanding the horizontal resolution by 96 pixels, increasing resolution from 256x224 to 352x224. Since the original SNES does not have this resolution, the emulator focused into high definition mods bsnes-hd must be used.

Vitor Vilela 1.3k Aug 2, 2022
mstatus is a super minimal entirely signal based statusbar for DWM.

mstatus is a uber-minimalistic signal based statusbar for DWM. All components of the statusbar are modules that must either be written by the user, or written by someone else and copied by the user.

Thomas Voss 1 Feb 2, 2022
Video, Image and GIF upscale/enlarge(Super-Resolution) and Video frame interpolation. Achieved with Waifu2x, SRMD, RealSR, Anime4K, RIFE, CAIN, DAIN and ACNet.

Video, Image and GIF upscale/enlarge(Super-Resolution) and Video frame interpolation. Achieved with Waifu2x, SRMD, RealSR, Anime4K, RIFE, CAIN, DAIN and ACNet.

Aaron Feng 7.3k Aug 11, 2022
Grand Theft Auto V + FidelityFx Super Resolution 1.0

Grand Theft Auto V + FidelityFx Super Resolution 1.0 This mod replaces original Grand Theft Auto V upscaler with FidelityFx Super Resolution 1.0 Origi

null 367 Aug 10, 2022
Simple command line tool that processes image files using the FidelityFX Super Resolution (FSR) or Contrast Adaptive Sharpening (CAS) shader systems.

Simple command line tool that processes image files using the FidelityFX Super Resolution (FSR) or Contrast Adaptive Sharpening (CAS) shader systems.

GPUOpen Effects 176 Jul 29, 2022
FidelityFX Super Resolution

FidelityFX Super Resolution 1.0 (FSR) Copyright (c) 2021 Advanced Micro Devices, Inc. All rights reserved. Permission is hereby granted, free of charg

GPUOpen Effects 1.8k Aug 12, 2022
Super Volume Render of Monte Carlo Path tracing for Linux

exposure-render-for-Linux Super Volume Render of Monte Carlo Path tracing for Linux Introduction The code is a Linux distribution of exposure render.

engineer 3 Aug 6, 2021
Implementing Deep Convolutional Neural Network in C without External Libraries for YUV video Super-Resolution

DeepC: Implementing Deep Convolutional Neural Network in C without External Libraries for YUV video Super-Resolution This code uses FSRCNN algorithm t

Milad Abdollahzadeh 8 Jul 13, 2022
🤟Super fast H.264/H.265 FLV player

??Super fast H.264/H.265 FLV player

Eros Zhao 1.2k Aug 12, 2022
Teach the C programming language using a collection of super beginner friendly tutorials and challenges.

TeachMeCLikeIm5 You are welcome to contribute to this repo. See the CONTRIBUTING.md for more info ?? About this repo ?? A collection of super beginner

inspirezonetech 10 Feb 4, 2022
super duper simple gui for C, wrapping imgui and stb

super duper simle gui for C, wrapping imgui and stb You can use it as a static library with cmake. See the example directory for a complete example. E

Rasmus 11 May 19, 2022
Dummy-Robot my super mini robot arm robot items

Dummy-Robot 我的超迷你机械臂机器人项目。 资料待整理 已添加3D模型设计源文件。 已添加夹爪硬件设计文件和LED灯环PCB 已添加无线空间定位控制器PCB文件 已添加无线示教器Peak软硬件工程(作为submodule) 已添加REF的硬件设计文件 已添加DummyStudio上位机 已

稚晖 8k Aug 10, 2022
New ultra super robust and fast programming language, fully supportable by G++ and Clang

Cplusplusplus New ultra super robust and fast programming language, fully supportable by G++ and Clang How to use: Just write #include <C+++.h> in you

Vladimir Melnikov 1 Nov 29, 2021
bsnes is a Super Nintendo (SNES) emulator focused on performance, features, and ease of use.

bsnes is a Super Nintendo (SNES) emulator focused on performance, features, and ease of use.

bsnes 1.2k Aug 3, 2022
Super paramagnetic Clustering - Marcelo Blatt, Shai Wiseman, and Eytan Domany (1996)

SPC: Super Paramagnetic Clustering Documentation The file README.PDF includes: installation instructions, example runs, file formats and parameter def

null 1 Nov 11, 2021