1

Objective

The goal is to extract the substrings TEST_CASE and RESULT from the string | TEST_CASE | RESULT | using regular expressions.

A possible solution

As an example [^\s*|] selects only the first character.

Question

What are examples of regular expressions that would extract the required substrings?

2
  • JavaScript? Java? C#? Commented Nov 16, 2018 at 18:58
  • 1
    I am revising all my past questions to make them useful to the community. I also added feedback below to the answers. Commented Apr 24, 2022 at 20:32

2 Answers 2

2

I believe that this should do it: /[^\s\|]+/g and use the g global flag.

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

Comments

2

You should use a quantifier to repeat the character class one or more times like [^\s|]+

A negated character class matches not what you have listed in the character class and is kind of a broad match.

Another option is to be specific about what you do want to match. If you only want to match uppercase characters and an underscore, you could use [A-Z_]+ or match 1+ times a word character \w+

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.