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

re.match does not seem to support seqs #11759

Closed
disruptek opened this issue Jul 16, 2019 · 5 comments
Closed

re.match does not seem to support seqs #11759

disruptek opened this issue Jul 16, 2019 · 5 comments
Labels

Comments

@disruptek
Copy link
Contributor

This runnable example from the documentation works fine:

var matches: array[2, string]
if match("abcdefg", re"c(d)ef(g)", matches, 2):
  for s in matches:
    echo s       # => d g

Although the signature suggests that it accepts an openArray for the matches variable, match() does not populate that var if a seq is supplied instead of an array. The proc does correctly identify whether a match exists between the source string an the regular expression pattern.

Example

var matches: seq[string]
if match("abcdefg", re"c(d)ef(g)", matches, 2):
  for s in matches:
    echo s       # =>

Current Output

Expected Output

d
g

Possible Solution

Call a spade a spade and demand an array for output.

Additional Information

Nim Compiler Version 0.20.99 [Linux: amd64]
Compiled at 2019-07-15
Copyright (c) 2006-2019 by Andreas Rumpf

git hash: 8550a8127c6c80754d8a6f4300e4c77ee126e6ec
active boot switches: -d:release
@kaushalmodi
Copy link
Contributor

kaushalmodi commented Jul 16, 2019

That's an interesting bug.. I thought this would reproduce the issue, but it doesn't!: https://play.nim-lang.org/#ix=1OHl works well.

See if you can tweak that example to reproduce the bug.

Refs:

@mratsim mratsim added the Regex label Jul 16, 2019
@kaushalmodi
Copy link
Contributor

Ok, the seq needs to be initialized to the required length, which can be done at run time too.

So this works: https://play.nim-lang.org/#ix=1OHt

@kaushalmodi
Copy link
Contributor

kaushalmodi commented Jul 16, 2019

May be an error should be thrown if Nim passes an unallocated or zero-length matches to pcre.

@narimiran
Copy link
Member

Duplicate of #9472 ?

@kaushalmodi
Copy link
Contributor

@narimiran Yes, this one is a duplicate.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants