Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

std/re find can't find matches #20966

Closed
iacore opened this issue Nov 29, 2022 · 2 comments
Closed

std/re find can't find matches #20966

iacore opened this issue Nov 29, 2022 · 2 comments

Comments

@iacore
Copy link
Contributor

iacore commented Nov 29, 2022

Description

The regex library doesn't work as advertised

import std/re

let s = "abcdefgabc1234abcdefg"
let r = re"abc(\d+)"
var matches: seq[string]
echo find(s, r, matches)
echo matches

Nim Version

Both 1.6.10 and devel

Current Output

7
@[]

Expected Output

7
@["1234"]

Possible Solution

No response

Additional Information

No response

@iacore
Copy link
Contributor Author

iacore commented Nov 29, 2022

It seems like the re library is very broken.

code:

import std/re

let s = "abcdefgabc1234abcdefg"
let r = re".*abc(\d+).*"
if s =~ r:
  echo matches

Output:

["1234", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", ""]

@Araq
Copy link
Member

Araq commented Dec 6, 2022

No bug here. You're supposed to use something like

import std/re

let s = "abcdefgabc1234abcdefg"
let r = re"abc(\d+)"
var matches: array[1, string]
echo find(s, r, matches)
echo matches

@Araq Araq closed this as completed Dec 6, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants