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

Regex Tester: Not matching correctly, Sql Select #885

Closed
horvaro opened this issue Jul 21, 2023 · 5 comments · Fixed by #983
Closed

Regex Tester: Not matching correctly, Sql Select #885

horvaro opened this issue Jul 21, 2023 · 5 comments · Fixed by #983
Labels
bug Something isn't working
Milestone

Comments

@horvaro
Copy link

horvaro commented Jul 21, 2023

Current behavior

Using the Regex Tester to find a simple regex for a SQL select statement.
I settled for ^(SELECT|select)\s.*\s(FROM|from)\s.*\s(WHERE|where)(\s.*\s=\s.*\s)*$ with the follwoing test data:

SELECT * FROM system:objects WHERE tag = 5
select city from system:objects WHERE name = 'name'
select city from system:objects WHERE name = 'name' and tag = 0
select name from table where
select name from table where 

The first three lines match. The two last ones dont.

How to reproduce it (as minimally and precisely as possible)

Open the Regex Tester.
Paste above mentioned regex.
Paste above mentioned test data.
First three lines match.

Expected behavior

None of the lines should match. I ran my code with that regex, and everything failed.
I cross-checked the Regex with regex101.com and found out that the regex tested in DevToys should not work.
The correct regex is: ^(SELECT|select)\s.*\s(FROM|from)\s.*\s(WHERE|where)\s(.*=\s.*)+$

Screenshots

No response

Workaround

No response

Affected platforms

Windows

Affected DevToys kind

DevToys (app with GUI)

DevToys Version

Version 1.0.12.0 | X64 | RELEASE | 94bb821 | 94bb821

Relevant Assets/Logs

No response

@horvaro horvaro added bug Something isn't working untriaged labels Jul 21, 2023
@veler veler removed the untriaged label Aug 6, 2023
@veler
Copy link
Collaborator

veler commented Nov 17, 2023

Hello,

From my understanding (please correct me if I'm wrong), when checking "Global" in Regex101, we get the same result than in DevToys, and DevToys behaves like if this Global option was checked.

When this Global option is unchecked, Regex101 only matches the first line. Do you know if you had this option checked on regex101.com?

image

I admit that in DevToys, it is not clear what behavior is expected. I'm planning to add this option in DevToys 2.0 (I'm currently working on it).

Thanks

@veler veler added this to the v2.0 milestone Nov 17, 2023
@horvaro
Copy link
Author

horvaro commented Nov 17, 2023

Yes, I ran it with global and multiline enabled. I also enabled multiline in DevToys.
The issue is with the first Regex, which I thought would work, because of the feedback from DevToys:

^(SELECT|select)\s.*\s(FROM|from)\s.*\s(WHERE|where)(\s.*\s=\s.*\s)*$
image

The same Regex (*$ at the end) gives truly another result on regex101:
image

After I corrected the Regex on regex101 (+$ at the end) the output is the same:
image

image

@veler
Copy link
Collaborator

veler commented Nov 18, 2023

That is quite interesting! Thanks for sharing!

@veler
Copy link
Collaborator

veler commented Nov 18, 2023

So, here is some good news 😁
I'm currently porting the RegEx Tester tool to DevToys 2.0, and I think I'm doing it better.

First, the regex that was producing some odd highlighting compared to Regex101.com now behaves as on Regex101:

image

Second, I added some colors to make the matches easier to group.

image

Does that look better?

Please note that this is a work in progress though. It's not done.

@horvaro
Copy link
Author

horvaro commented Nov 18, 2023

Thank you very much for sharing!
Yes, that looks indeed promissing 👍
I am looking forward to the release 2.0

@horvaro horvaro closed this as completed Nov 18, 2023
@veler veler reopened this Nov 20, 2023
@veler veler linked a pull request Nov 20, 2023 that will close this issue
18 tasks
@veler veler closed this as completed Nov 25, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants