We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
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
StringScanner lost data with the code below:
var content = 'xxxx[fn=4][fn=37][fn=36][fn=12][fn=26]xxxx'; var _scanner = StringScanner(content); while (!_scanner.isDone) { if (_scanner.scan(RegExp('\\[fn=(\\d+)]'))) { print(content.substring(_scanner.lastMatch!.start + 1, _scanner.lastMatch!.end - 1)); } if (!_scanner.isDone) { _scanner.position++; } }
the result is :
I/flutter (25050): fn=4 I/flutter (25050): fn=36 I/flutter (25050): fn=26
but If I use this method directly:
var allMatches = RegExp('\\[fn=(\\d+)]').allMatches(content); for (var element in allMatches) { print('--${element.start}'); }
I got the right answer:
I/flutter (25050): [fn=4] I/flutter (25050): [fn=37] I/flutter (25050): [fn=36] I/flutter (25050): [fn=12] I/flutter (25050): [fn=26]
something lost when I use StringScanner.
The text was updated successfully, but these errors were encountered:
Please try this code
if (_scanner.scan(RegExp('\\[fn=(\\d+)]'))) { print(content.substring(_scanner.lastMatch!.start + 1, _scanner.lastMatch!.end - 1)); } else { _scanner.position++; }
Some methods move the pointer forward while others don't.
Sorry, something went wrong.
Please try this code if (_scanner.scan(RegExp('\\[fn=(\\d+)]'))) { print(content.substring(_scanner.lastMatch!.start + 1, _scanner.lastMatch!.end - 1)); } else { _scanner.position++; } Some methods move the pointer forward while others don't.
It works! thank u very much~
ps: Is StringScaner more efficient than using regular expressions directly?
Looking at your code, I can say you should use RegExp directly.
RegExp
No branches or pull requests
StringScanner lost data with the code below:
the result is :
but If I use this method directly:
I got the right answer:
something lost when I use StringScanner.
The text was updated successfully, but these errors were encountered: