0

I have a list of strings and I want to remove each string from the list that matches any of the regex patterns from another list. I have solved it this way, however, I know there is a better way to do so. For example:

Regex_list := ["^reg\ex1", "/^\d+$/", "^Apple"]

String_list := ["Apple", "Banana", "Pair" "12345"]

Want - {Banana, Pair}

I don't know my regex, but for this example lets say Apple and 12345 match the last 2 on the regex list. I want to have a list only containing Banana and Pair.

My take:

string_list := input.string_list[_]

match := {x | x := string_list; regex.match(data.regex_list[_], x)} --> {Apple, 12345}

dont_match := string_list - match --> {"Banana", "Pair"}

1 Answer 1

1

I think that is the best way. Alternatively you could use a rule to build a set of matches, but the principle would be the same.

matches[s] {
    r := [`^reg\ex1`, `^\d+$`, `^Apple`][_]
    s := ["Apple", "Banana", "Pair", "12345"][_]
    
    regex.match(r, s)
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.