Skip to content

Commit a3b7492

Browse files
authored
Change variable names for clarity in regex examples (#6424)
This update improves the variable naming in the Dart regex example for accurate understanding: - Renamed `numbers` → `digitSequence`. - Renamed `allCharacters` → `lettersOnly` . This changes are made in two directories: 1) `/examples/misc/test/library_tour/core_test.dart` 2) `/src/content/libraries/dart-core.md` This ensures and follows the contributing guidelines. As per the wish, the variables name are modified for greater understanding. Fixes #6410
1 parent 22a648f commit a3b7492

File tree

2 files changed

+16
-16
lines changed

2 files changed

+16
-16
lines changed

examples/misc/test/library_tour/core_test.dart

+8-8
Original file line numberDiff line numberDiff line change
@@ -166,32 +166,32 @@ void main() {
166166
test('RegExp', () {
167167
// #docregion regexp
168168
// Here's a regular expression for one or more digits.
169-
var numbers = RegExp(r'\d+');
169+
var digitSequence = RegExp(r'\d+');
170170

171-
var allCharacters = 'llamas live fifteen to twenty years';
171+
var lettersOnly = 'llamas live fifteen to twenty years';
172172
var someDigits = 'llamas live 15 to 20 years';
173173

174174
// contains() can use a regular expression.
175-
assert(!allCharacters.contains(numbers));
176-
assert(someDigits.contains(numbers));
175+
assert(!lettersOnly.contains(digitSequence));
176+
assert(someDigits.contains(digitSequence));
177177

178178
// Replace every match with another string.
179-
var exedOut = someDigits.replaceAll(numbers, 'XX');
179+
var exedOut = someDigits.replaceAll(digitSequence, 'XX');
180180
assert(exedOut == 'llamas live XX to XX years');
181181
// #enddocregion regexp
182182
});
183183

184184
test('match', () {
185185
void testMatch() {
186186
// #docregion match
187-
var numbers = RegExp(r'\d+');
187+
var digitSequence = RegExp(r'\d+');
188188
var someDigits = 'llamas live 15 to 20 years';
189189

190190
// Check whether the reg exp has a match in a string.
191-
assert(numbers.hasMatch(someDigits));
191+
assert(digitSequence.hasMatch(someDigits));
192192

193193
// Loop through all matches.
194-
for (final match in numbers.allMatches(someDigits)) {
194+
for (final match in digitSequence.allMatches(someDigits)) {
195195
print(match.group(0)); // 15, then 20
196196
}
197197
// #enddocregion match

src/content/libraries/dart-core.md

+8-8
Original file line numberDiff line numberDiff line change
@@ -255,17 +255,17 @@ matching of strings.
255255
<?code-excerpt "misc/test/library_tour/core_test.dart (regexp)"?>
256256
```dart
257257
// Here's a regular expression for one or more digits.
258-
var numbers = RegExp(r'\d+');
258+
var digitSequence = RegExp(r'\d+');
259259
260-
var allCharacters = 'llamas live fifteen to twenty years';
260+
var lettersOnly = 'llamas live fifteen to twenty years';
261261
var someDigits = 'llamas live 15 to 20 years';
262262
263263
// contains() can use a regular expression.
264-
assert(!allCharacters.contains(numbers));
265-
assert(someDigits.contains(numbers));
264+
assert(!lettersOnly.contains(digitSequence));
265+
assert(someDigits.contains(digitSequence));
266266
267267
// Replace every match with another string.
268-
var exedOut = someDigits.replaceAll(numbers, 'XX');
268+
var exedOut = someDigits.replaceAll(digitSequence, 'XX');
269269
assert(exedOut == 'llamas live XX to XX years');
270270
```
271271

@@ -274,14 +274,14 @@ provides access to a regular expression match.
274274

275275
<?code-excerpt "misc/test/library_tour/core_test.dart (match)"?>
276276
```dart
277-
var numbers = RegExp(r'\d+');
277+
var digitSequence = RegExp(r'\d+');
278278
var someDigits = 'llamas live 15 to 20 years';
279279
280280
// Check whether the reg exp has a match in a string.
281-
assert(numbers.hasMatch(someDigits));
281+
assert(digitSequence.hasMatch(someDigits));
282282
283283
// Loop through all matches.
284-
for (final match in numbers.allMatches(someDigits)) {
284+
for (final match in digitSequence.allMatches(someDigits)) {
285285
print(match.group(0)); // 15, then 20
286286
}
287287
```

0 commit comments

Comments
 (0)