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 groupCount varies between JavaScript vs Dart. #11674

Closed
DartBot opened this issue Jul 3, 2013 · 4 comments
Closed

RegEx groupCount varies between JavaScript vs Dart. #11674

DartBot opened this issue Jul 3, 2013 · 4 comments
Labels
area-vm Use area-vm for VM related issues, including code coverage, FFI, and the AOT and JIT backends. closed-obsolete Closed as the reported issue is no longer relevant

Comments

@DartBot
Copy link

DartBot commented Jul 3, 2013

This issue was originally filed by demis.bell...@gmail.com


Dart only returns 4 groups whilst the same RegEx in JS returns 5 groups:

//Dart
var splitPathRe =
    new RegExp(r"^(/?|)([\s\S]?)((?:.{1,2}|[^\/]+?|)(.[^.\/]|))(?:[/]*)$");

main(){
  Match m = splitPathRe.firstMatch('/path.to/.file');
  print(m.groupCount); //4
  var groups = [];
  for (var i=0; i<m.groupCount; i++)
    groups.add(i);
  print(m.groups(groups)); //[/path.to/.file, /, path.to/, .file]
}

/* JavaScript:
  /^(/?|)([\s\S]?)((?:.{1,2}|[^\/]+?|)(.[^.\/]|))(?:[/]*)$/.exec('/path.to/.file')
  //["/path.to/.file", "/", "path.to/", ".file", ""] //length = 5
*/

@DartBot
Copy link
Author

DartBot commented Jul 3, 2013

This comment was originally written by demis.b...@gmail.com


The issue is with the last group which is visible when increasing the group by 1, e.g:

  for (var i=0; i<=m.groupCount; i++)
    groups.add(i);
  print(m.groups(groups));

//Dart: [/path.to/.file, /, path.to/, .file, .file]
//JS: ["/path.to/.file", "/", "path.to/", ".file", ""]

@anders-sandholm
Copy link
Contributor

Not sure if the issue is with the VM or dart2js...


Added Area-VM, Triaged labels.

@DartBot
Copy link
Author

DartBot commented Jul 3, 2013

This comment was originally written by demis.b...@gmail.com


Sorry this error is when running in the latest DartVM, I get the same results as JS when running on http://try.dartlang.org

@lrhn
Copy link
Member

lrhn commented Sep 29, 2014

There seems to be no difference now.


Added AssumedStale label.

@DartBot DartBot added Type-Defect area-vm Use area-vm for VM related issues, including code coverage, FFI, and the AOT and JIT backends. closed-obsolete Closed as the reported issue is no longer relevant labels Sep 29, 2014
This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-vm Use area-vm for VM related issues, including code coverage, FFI, and the AOT and JIT backends. closed-obsolete Closed as the reported issue is no longer relevant
Projects
None yet
Development

No branches or pull requests

3 participants