grep function

StreamTransformer<String, String> grep(
  1. String regexp, {
  2. bool exclude = false,
  3. bool onlyMatching = false,
  4. bool caseSensitive = true,
  5. bool unicode = false,
  6. bool dotAll = false,
})

Returns a transformer that emits only the elements of the source stream that match regexp.

Note that unlike the command-line grep program, this won't emit a ScriptException even if it matches nothing.

If exclude is true, instead returns the elements of the source stream that don't match regexp.

If onlyMatching is true, this only prints the non-empty matched parts of each line. Prints each match on a separate line. This flag can't be true at the same time as exclude.

The caseSensitive, unicode, and dotAll flags are the same as for new RegExp.

Implementation

StreamTransformer<String, String> grep(String regexp,
    {bool exclude = false,
    bool onlyMatching = false,
    bool caseSensitive = true,
    bool unicode = false,
    bool dotAll = false}) {
  if (exclude && onlyMatching) {
    throw ArgumentError("The exclude and onlyMatching flags can't both be set");
  }

  return NamedStreamTransformer.fromBind(
      "grep",
      (stream) => stream.grep(regexp,
          exclude: exclude,
          onlyMatching: onlyMatching,
          caseSensitive: caseSensitive,
          unicode: unicode,
          dotAll: dotAll));
}