parseAllReferences function

List<Reference> parseAllReferences(
  1. String stringReference, {
  2. List<String> excludeList = const ['Is', 'is', 'Song', 'song', 'Am', 'am', 'songs', 'act', 'acts', 'mark'],
})

Finds all the references within a string. Returns an empty list when no references are found.

parseAllReferences('I love James 4:5 and Matthew 2:4');

Returns a list of Reference objects with James 4:5 and Matthew 2:4

Note: The word 'is' will be parsed as the book of Isaiah. An efficient workaround is in the works.

Implementation

List<Reference> parseAllReferences(String stringReference, {List<String> excludeList = const ['Is','is','Song','song','Am','am','songs','act','acts', 'mark']}) {
  var refs = <Reference>[];
  var matches = _exp.allMatches(stringReference);
  matches = matches.where((x) {
    var matchedString = x.group(0)?.trim();

    // Check if any of the excluded words are contained in the matchedString
    return matchedString != null && !excludeList.any((e) => matchedString.contains(RegExp(r'\b' + e + r'\b', caseSensitive: true)));
  });

  matches.forEach((x) => refs.add(_createRefFromMatch(x)));
  return refs;
}