How about

^[(Administrators)(LOCAL SERVICE)(NETWORK SERVICE),\s]+$

or

^(Administrators|LOCAL SERVICE|NETWORK SERVICE|[,\s])+$

see working at https://regex101.com/r/oJF0aW/2/tests

both versions basically say that the whole string must contain only the specified user names as well as commas and whitespace.

Answer from nozzleman on Stack Overflow
๐ŸŒ
O'Reilly
oreilly.com โ€บ library โ€บ view โ€บ regular-expressions-cookbook โ€บ 9781449327453 โ€บ ch05s02.html
5.2. Find Any of Multiple Words - Regular Expressions Cookbook, 2nd Edition [Book]
August 27, 2012 - Any regex metacharacters within the accepted words are escaped // with a backslash before searching. function matchWords(subject, words) { var regexMetachars = /[(){[*+?.\\^$|]/g; for (var i = 0; i < words.length; i++) { words[i] = words[i].replace(regexMetachars, "\\$&"); } var regex = new RegExp("\\b(?:" + words.join("|") + ")\\b", "gi"); return subject.match(regex) || []; } matchWords(subject, ["one","two","three"]); // Returns an array with four matches: ["One","two","one","three"]
Authors ย  Jan GoyvaertsSteven Levithan
Published ย  2012
Pages ย  609
Discussions

Multiple words in any order using regex - Stack Overflow
As the title says , I need to find two specific words in a sentence. But they can be in any order and any casing. How do I go about doing this using regex? For example, I need to extract the words... More on stackoverflow.com
๐ŸŒ stackoverflow.com
python 3.x - Match multiple words in any order via one regex - Stack Overflow
You asked us not to ask, but I just have to: When finding the values for multiple different keys, wouldn't it be very helpful to know which keys those values belong to? ... You may leverage a non-capturing alternation group to match either VERSION or FREQ (optionally preceded with a word boundary, ... More on stackoverflow.com
๐ŸŒ stackoverflow.com
November 13, 2017
python - Match a list of possible words in a string in any order - Stack Overflow
I know this question sounds similar to others, but see my notes below on those solutions. I need a regex to use in Python to search for specific words in any order in a string. What I want to do is... More on stackoverflow.com
๐ŸŒ stackoverflow.com
January 6, 2021
python - Match regex in any order - Stack Overflow
I want to check for complex password with regular expression. It should have 1 number 1 uppercase and one lowercase letter, not in specific order. So i though about something like this: m = re.se... More on stackoverflow.com
๐ŸŒ stackoverflow.com
๐ŸŒ
py4u
py4u.org โ€บ blog โ€บ python-regular-expression-match-multiple-words-anywhere
How to Match Multiple Words Anywhere in a String with Python Regular Expressions (Regardless of Order or Position)
Use Word Boundaries (\b): Avoid partial matches (e.g., \bapple\b vs. apple to exclude "apples"). Escape Special Characters: Always use re.escape() if words contain regex metacharacters (+, ., *, etc.). ... Empty strings (text = "" โ†’ should return False). Words not present (text = "apple banana" โ†’ missing "cherry" โ†’ False). Mixed order and punctuation. Use Raw Strings (r''): Prevents Python from interpreting backslashes (e.g., r'\b' vs.
๐ŸŒ
Quora
quora.com โ€บ How-can-I-write-a-Python-regex-to-match-multiple-words
How to write a Python regex to match multiple words - Quora
Answer (1 of 2): > Q: How can I write a Python regex to match multiple words? An answer is provided in Hasi Syed's answer to How can I write a Python regex to match multiple words?. I would like to stress the following: * beware, regular expressions are by default greedy, that is, they match a...
๐ŸŒ
TutorialsPoint
tutorialspoint.com โ€บ How-to-write-a-Python-regular-expression-to-match-multiple-words-anywhere
How to write a Python regular expression to match multiple words anywhere?
February 20, 2020 - import re s = "These are roses and lilies and orchids, but not marigolds or .." r = re.compile(r'\broses\b | \bmarigolds\b | \borchids\b', flags=re.I | re.X) print r.findall(s)
Find elsewhere
๐ŸŒ
regex101
regex101.com โ€บ library โ€บ fA2RAC
regex101: Matching multiple words in any order in the same string
This regex will match any Youtube video ID thrown at it and return one capturing group containing the ID.Submitted by Jacob Overgaard
๐ŸŒ
Python documentation
docs.python.org โ€บ 3 โ€บ library โ€บ re.html
re โ€” Regular expression operations โ€” Python 3.14.3 ...
5 days ago - The string is scanned left-to-right, and matches are returned in the order found. Empty matches are included in the result. The result depends on the number of capturing groups in the pattern. If there are no groups, return a list of strings matching the whole pattern. If there is exactly one group, return a list of strings matching that group. If multiple groups are present, return a list of tuples of strings matching the groups.
๐ŸŒ
CopyProgramming
copyprogramming.com โ€บ howto โ€บ how-to-match-multiple-words-in-regex
Regex: Matching Multiple Words Using Regular Expressions
April 5, 2023 - This pattern will match any letter, ... as described in the Syntax Class Table. Multiple words in any order using regex, You're better off with programming the software to be case insensitive....
๐ŸŒ
CopyProgramming
copyprogramming.com โ€บ howto โ€บ multiple-words-in-any-order-using-regex
Regex: Regex for Matching Multiple Words in Any Order
April 2, 2023 - See the Python demo. ... Unfortunately, regex cannot match in the specific order you desire. One workaround is to first execute the section before the | symbol, followed by the section after it. Alternatively, you can sort the output after executing the regex.
๐ŸŒ
LearnByExample
learnbyexample.github.io โ€บ py_regular_expressions โ€บ alternation-and-grouping.html
Alternation and Grouping - Understanding Python re(gex)?
>>> words = 'lion elephant are rope not' # span shows the start and end+1 index of the matched portion # match shows the text that satisfied the search criteria >>> re.search(r'on', words) &LTre.Match object; span=(2, 4), match='on'> >>> re.search(r'ant', words) &LTre.Match object; span=(10, 13), match='ant'> # starting index of 'on' < index of 'ant' for the given string input # so 'on' will be replaced irrespective of order # count optional argument here restricts no.
๐ŸŒ
CopyProgramming
copyprogramming.com โ€บ howto โ€บ regex-to-match-multiple-words-in-a-string
Regex: Matching several words within a string using regular expressions
May 29, 2023 - Using Regular Expressions to Match Multiple Words in Any Order [Duplicate], Matching Multiple Words Enclosed in Braces with Underscore Delimiters, while Ignoring Characters at String's Start/End, Creating a Python Regular Expression to Locate Multiple Words in Any Position, Searching for Multiple ...
๐ŸŒ
Reddit
reddit.com โ€บ r/regex โ€บ match two words anywhere in text
r/regex on Reddit: Match two words anywhere in text
April 19, 2024 -

I'm very new to RegEx, but I'm trying to learn.

I'm looking to match two words which can be present anywhere in a body of text, separated by multiple line breaks/characters.

For example, let's say I want to match the word "apple" and "dog". It should match only if both words are present somewhere in the text. It can also be in any order.

It could be in something like:

Testing

Testing 2

Dog

Testing 3

Apple

I've tried things like: (apple)(dog) (apple)((.|\n)*)dog

(apple)((.|\n)*)dog works, but doesn't support the "any order"

What am I missing?

๐ŸŒ
freeCodeCamp
forum.freecodecamp.org โ€บ t โ€บ regex-to-match-string-containing-two-words-in-any-order โ€บ 333791
Regex to match string containing two words in any order - The freeCodeCamp Forum
December 16, 2019 - Hi guys, I want to search a string with two , maybe three words , maybe more โ€ฆ But the basic idea is this: If I have a string like "Hello my name is Jack and this is Matt." And I have a working regex like this: ^(?=.*\bjack\b)(?=.*\bmatt\b).*$ However, itโ€™s hard-coded.
๐ŸŒ
Reddit
reddit.com โ€บ r/learnpython โ€บ regular expressions: how can i match multiple groups in any order multiple times?
r/learnpython on Reddit: Regular expressions: How can I match multiple groups in any order multiple times?
June 2, 2022 -

Let's say I have the following list of strings that I want to match:

['ab', 'cde', 'abb', 'efbc']

Is there a way to write a single RE that will match any string that contains any amount of these strings in any order?

So for example, all of these would be valid matches:

abcdeabb
ababbefbc
efbccdeab
cdecdeabefbcab
ababababab

If you don't feel like working it out, I'd appreciate any general guidance as well, such as what I need to look into. Perhaps look-ahead and/or look-behind? I'm not familiar with those.

Thanks!

๐ŸŒ
Quora
quora.com โ€บ How-can-I-search-for-a-multiple-word-string-in-regex
How to search for a multiple-word string in regex - Quora
There are several standards and usages for regex, and I most often use it in the vi - Wikipedia text editor, but also in the Python language via the re - Regular expression operations - Python 3.7.4 documentation module. To give you the flavor, some basic operations are: Many characters or sequences match themselves (i.e., โ€˜aโ€™ matches a, โ€˜abโ€™ matches ab).