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

Bug or missunderstanding #25

Open
Neewd opened this issue Sep 19, 2017 · 1 comment
Open

Bug or missunderstanding #25

Neewd opened this issue Sep 19, 2017 · 1 comment

Comments

@Neewd
Copy link

Neewd commented Sep 19, 2017

Hi,

I'm using balanced-match to isolate the body of a function (all between brackets)
So, I assume during my test that a function is begining by the same pattern (scope function name params {) and finishing by a bracket (with positive lookahead to see if the next caracters are a new function)

Here is my two regex :
firstRegex : /(override)?\s?(public|private|protected)\s(?:function)\s(get)?\s?(\w*)\s?\((.*)\)\s?:?\s?(\w*)\s*{/
secondRegex : /}(\s)*(?=override|public|private|protected|(}\s*}))/

It's working fine except for the last function who is not followed by a new function but by two brackets (for the end of the class and the end of package)

I have tested my two regex on regex101 and it's working fine (https://regex101.com/r/A7jQDr/1) but when I test with balanced-match it didn't match the same way regex101 does.
Here is my test on RunKit : https://runkit.com/59c0dc7528f14c00126b4314/59c0dc7662f5730012fd1760

As you can see, the match.post contains a extra bracket ..

If someone can tell me what's wrong.

@chinesedfan
Copy link

@Neewd You 3 regexps are not the same.

  • in the issue description, /}(\s)(?=override|public|private|protected|(}\s}))/
  • in regex101.com, }(?:\s)*(?=override|public|private|protected|(?:}(\s|\n)+}$))
  • in runkit.com, /(}(?:\s)*(?=override|public|private|protected)|}\s+}\s+}$)/

Only the second one in regex101.com is the right one.

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

No branches or pull requests

2 participants