Basic idea: run model in batch mode
The easiest way I see is to create a model and then run it in batch mode, to get one output for each input (letter
C). I first show the basic steps how to create the model, in a second paragraph I show a more refined model that only leaves the features you want as a result.
You can download the final model here to use it or adapt it to your neeeds. Run the model in batch mode by inserting you inputs like
C etc. (see step 2 with screenshots for details how to run the model in batch mode).
Screenshot (here with polygons; runs the same with lines or points): labels with attribute values of
field2 of the initial layer; in color output polygons of the model like follows: blue polygons: containing
A; red line pattern: containing
B; yellow outlined: containing
C; all three layers contain just one (multipart) feature = merged/aggregated all input polygons containing the respective text string:
Basic steps to create model
Create the model with two inputs (
vector_input) and one algorithm
Aggregate. Settings in Aggregate: for Input layer set mode to
Using model input and select the
Group by expression, for
array_contains (array ("field1","field2"),@text_input) where
@text_input is a variable QGIS creates automatically based on the name of
Save and run the model in Batch mode, add as many rows as you have values and fill in the values (
C) in text_input:
Find the model linked at the beginning of this answer.
Using aggregate, you'll get one output feature for the input features that contain the attribute and another feature for those that do not contain the attribute. We want to keep only the first feature.
For this, we add a
Select by Expression algorithm with the expression set to
Pre-calculated value and the content
'regexp_match (concat,''(.' || @text_input || '.)'')>0'. This selects the feature that contains the text based on which we want to aggregate.
Now based on this selection, add an
Extract selected features algorithm with inuput layer set to
Algorithm Output and selecting the
Select by expression output (see screenshot).