Skip to content

regex matches_string result error. #24159

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

Open
meiseayoung opened this issue Apr 8, 2025 · 10 comments
Open

regex matches_string result error. #24159

meiseayoung opened this issue Apr 8, 2025 · 10 comments
Labels
Bug This tag is applied to issues which reports bugs.

Comments

@meiseayoung
Copy link

meiseayoung commented Apr 8, 2025

Describe the bug

reg_pattern := r'/api/(\w+/){0,}\w+/user$'
reg := regex.regex_opt(reg_pattern) or { panic(err) }
str : = '/api/v1/user'
result : = reg.matches_string(str)
assert result == true

left value: result = false
right value: true
V panic: Assertion failed...

Reproduction Steps

none

Expected Behavior

expexct assert test pass

Current Behavior

assert test failed

Possible Solution

No response

Additional Information/Context

No response

V version

0.4.10 54c10ec

Environment details (OS name and version, etc.)

V full version V 0.4.10 54c10ec.54c10ec
OS windows, Microsoft Windows 10 19045 64-bit
Processor 4 cpus, 64bit, little endian, Intel(R) Core(TM) i5-7400 CPU @ 3.00GHz
Memory 2.57GB/15.91GB
V executable F:\v\v.exe
V last modified time 2025-03-24 06:08:50
V home dir OK, value: F:\v
VMODULES OK, value: C:\Users\admin.vmodules
VTMP OK, value: C:\Users\admin\AppData\Local\Temp\v_0
Current working dir OK, value: C:\Users\admin\Downloads\v
Git version git version 2.34.1.windows.1
V git status Error: fatal: not a git repository (or any of the parent directories): .git
.git/config present false
cc version N/A
gcc version N/A
clang version clang version 17.0.6
msvc version N/A
tcc version tcc version 0.9.27 (x86_64 Windows)
tcc git status N/A
emcc version N/A
glibc version N/A

Note

You can use the 👍 reaction to increase the issue's priority for developers.

Please note that only the 👍 reaction to the issue itself counts as a vote.
Other reactions and those to comments will not be taken into account.

@meiseayoung meiseayoung added the Bug This tag is applied to issues which reports bugs. label Apr 8, 2025
Copy link

Connected to Huly®: V_0.6-22548

@penguindark
Copy link
Member

penguindark commented Apr 11, 2025

Can you please elaborate what do you want achieve with the query r'/api/(\w+/){0,}\w+/user$'?
The (\w+/){0,}\w+ what want to catch?
In particular this part: (\w+/){0,} that can be written as: (\w+/)*
Can you show more examples?

@meiseayoung
Copy link
Author

Can you please elaborate what do you want achieve with the query r'/api/(\w+/){0,}\w+/user$'? The (\w+/){0,}\w+ what want to catch? In particular this part: (\w+/){0,} that can be written as: (\w+/)* Can you show more examples?

i want build api request path regex
/api/**/user to /api/(\w+/)*\w+/user$

the javascript same regex match result is true

Image

@penguindark
Copy link
Member

If I'm correct you want match all cases of: /API/level1/level2/.. ../user where at least one level is present.
Am I right?

example:

import regex
q := r'^/api/(\w+/)+user$'
mut re := regex.regex_opt(q) or { panic(err) }
println(re.get_query())
txt := '/api/V1/user'
res := re.matches_string(txt)
println(res)

return true

@meiseayoung
Copy link
Author

If I'm correct you want match all cases of: /API/level1/level2/.. ../user where at least one level is present. Am I right?

example:

import regex
q := r'^/api/(\w+/)+user$'
mut re := regex.regex_opt(q) or { panic(err) }
println(re.get_query())
txt := '/api/V1/user'
res := re.matches_string(txt)
println(res)
return true

the regex is dynamic
/api/**/user to /api/(\w+/)*\w+/user$
/api/** to /api/(\w+/)*\w+$

@penguindark
Copy link
Member

Sorry but I'm not understanding what exactly you want match, what do you mean for dynamic?
Can you write down few examples of the cases you want match? Does "user" must be always present?
Please remember that V regex is a base regex, if you need more complex behavior please use the PCRE module.

@meiseayoung
Copy link
Author

the source code
https://github.com/meiseayoung/v-hono/blob/main/hono/app.v

Image
i change the regex string to r'[^#\?]+', then it works.

you can run it with command v run src/http_server.v

@meiseayoung
Copy link
Author

Sorry but I'm not understanding what exactly you want match, what do you mean for dynamic? Can you write down few examples of the cases you want match? Does "user" must be always present? Please remember that V regex is a base regex, if you need more complex behavior please use the PCRE module.

I uploaded the sourcecode,
and i am not found the PCRE module in the v stdlib.

@penguindark
Copy link
Member

I see that you changed the regex query, good.
To use PCRE you have to install it, please have a look here: https://github.com/vlang/pcre
You can install this module using v install pcre, and then use it with import pcre.

@meiseayoung
Copy link
Author

I see that you changed the regex query, good. To use PCRE you have to install it, please have a look here: https://github.com/vlang/pcre You can install this module using v install pcre, and then use it with import pcre.

thank you very much. i am just see the pcre module, it's not frendly to catch group.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug This tag is applied to issues which reports bugs.
Projects
None yet
Development

No branches or pull requests

2 participants