0

I have a regular expression that matches < preceded by another <

This is I am using (?<=<)< and it works properly.

However, when I use the string-match function to search for the pattern in a string, it throws an error.

Here is the code I am using:

(string-match "(?<=<)<" "Test<<2")

The error it shows:

ERROR: In procedure make-regexp:

ERROR: In procedure make-regexp: Invalid preceding regular expression

Does Scheme support lookbehind regex? If so, what am I doing wrong here? If not, is there a way I can make this work

Community
  • 1
  • 1
xabush
  • 849
  • 1
  • 13
  • 29
  • 2
    Where is `(?<=<)<` working properly? See [Guile docs](https://www.gnu.org/software/guile/manual/html_node/Regexp-Functions.html), saying *Guile supports POSIX extended regular expressions*. POSIX regex does not support lookarounds. Also, why not just use `<<`? What is your final goal? – Wiktor Stribiżew Sep 25 '17 at 11:18
  • Note that `string-match` and regular expressions are not part of any Scheme standard and thus it would be wrong to call it Scheme regex.. It is *Guile regex* and *Does guile support...*. Other Scheme implementations also have their own which again is not compatible with Guile. If you see to SRFI then you have [SRFI-115](https://srfi.schemers.org/srfi-115/srfi-115.html#proc-regexp) and it has optional lookaround thus you need to use `cond-expand` to enforce a implementation that has it and lookaround and you need to learn a whole new regexp syntax. – Sylwester Sep 25 '17 at 12:25
  • @Sylwester So, how can I use the `srfi-115` modules ? When I try to import it using `(use-modules (srfi srfi-115))` I get _no code for module_ error – xabush Sep 26 '17 at 08:04
  • As with all SRFIs you need to [check if your implementation has implemented it](https://www.gnu.org/software/guile/manual/html_node/SRFI-Support.html) and in the case it hasn't it might work to use the [SRFIs reference implementation](https://srfi.schemers.org/srfi-115/srfi-115.html#Implementation). In this case however it seems lik ethe code is written in R7RS which would pose a challenge if your implementation does not yet support R7RS-small. – Sylwester Sep 26 '17 at 11:59

0 Answers0