0

My code has five different Regex strings:

            Regex regex = new Regex(@"(\n  )?\[see=[^\]]*\]]");

            phraseSources
                .ToList()
                .ForEach(item => item.JmdictMeaning = regex.Replace(item.JmdictMeaning, ""));

            regex = new Regex(@"(\n  )?\[note=[^\]]*\]");

            phraseSources
                .ToList()
                .ForEach(item => item.JmdictMeaning = regex.Replace(item.JmdictMeaning, ""));

            regex = new Regex(@"(\n  )?\[restr=[^\]]*\]");

            phraseSources
                .ToList()
                .ForEach(item => item.JmdictMeaning = regex.Replace(item.JmdictMeaning, ""));

            regex = new Regex(@"(\n  )?\[ant=[^\]]*\]");

            phraseSources
                .ToList()
                .ForEach(item => item.JmdictMeaning = regex.Replace(item.JmdictMeaning, ""));

            regex = new Regex(@"(\n  )?\[syn=[^\]]*\]");

            phraseSources
                .ToList()
                .ForEach(item => item.JmdictMeaning = regex.Replace(item.JmdictMeaning, ""));

Is there a way that I can combine these into just one Regex?

2
  • Could you provide some examples of matching text for each regex? Commented Oct 27, 2019 at 10:22
  • "Is there a way that I can combine these into just one Regex?" -- there are multiple ways to combine two regexes into a single one. It depends on what to you want to achieve with the new regex. Commented Oct 27, 2019 at 10:44

2 Answers 2

1

You can use or operator inside inner group

(\n  )?\[((see|note|ant|restr|syn)=[^\]]*)\]

https://regex101.com/r/CyHvNh/1

Sign up to request clarification or add additional context in comments.

Comments

0

Use the | operator and group all with parentesis ()

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.