findPreviousParsed method

  1. @override
Node? findPreviousParsed({
  1. RegExp? pattern,
  2. int? nodeType,
})
inherited

These methods use previousParsed to iterate over the tags, comments, strings, etc. that came before it in the document.

The findPreviousParsedAll method returns all matches, and findPreviousParsed only returns the first match.

Filters:

- pattern, to search only for occurrences that satisfy the RegExp match.

- nodeType, what type of node/element to search.

  • Node.ATTRIBUTE_NODE = 2;
  • Node.CDATA_SECTION_NODE = 4;
  • Node.COMMENT_NODE = 8;
  • Node.DOCUMENT_FRAGMENT_NODE = 11;
  • Node.DOCUMENT_NODE = 9;
  • Node.DOCUMENT_TYPE_NODE = 10;
  • Node.ELEMENT_NODE = 1;
  • Node.ENTITY_NODE = 6;
  • Node.ENTITY_REFERENCE_NODE = 5;
  • Node.NOTATION_NODE = 12;
  • Node.PROCESSING_INSTRUCTION_NODE = 7;
  • Node.TEXT_NODE = 3;
// find all url links within the text node
final nextParsed = bs.findNextParsed(
  pattern: RegExp(r'.*(.com)'),
  nodeType: Node.TEXT_NODE,
);

Implementation

@override
Node? findPreviousParsed({
  RegExp? pattern,
  int? nodeType,
}) {
  final filtered =
      findPreviousParsedAll(pattern: pattern, nodeType: nodeType);
  return filtered.firstOrNull;
}