parsePlace function
Finds all the places within a string. Returns an empty list when no places are found.
parsePlace('I visited Jerusalem and Damascus.');
Returns a list of matched places.
Implementation
/// list when no places are found.
///
/// ```dart
/// parsePlace('I visited Jerusalem and Damascus.');
/// ```
/// Returns a list of matched places.
List<String> parsePlace(String stringReference) {
var matchedPlaces = <String>[];
var normalizedString = stringReference.toLowerCase();
PlaceData.places.forEach((place) {
// Use word boundaries to ensure whole word matches
var placePattern = RegExp(r'\b' + RegExp.escape(place.toLowerCase()) + r'\b');
// If the pattern matches in the normalized string, add the place to matched places
if (placePattern.hasMatch(normalizedString)) {
matchedPlaces.add(place);
}
});
return matchedPlaces;
}