0

I am trying to get all the words comes with inside bracket in string using javascript but i am not get clear idea. please help me.

Input

"  (  [Field1]  +  [Field2]  )    +    (  [Field3]  -  [Field4]  )  "

Required Output

["Field1","Field2","Field3","Field4"]

Thanks in advance

5
  • 1
    So, tried some basic regex yet? Commented Oct 27, 2016 at 11:12
  • Wiktor Stribiżew I will start to learn regex. thanks Commented Oct 27, 2016 at 11:17
  • Starting to learn by doing nothing will not help. Do all lessons at regexone.com, read through regular-expressions.info, regex SO tag description (with many other links to great online resources), and the community SO post called What does the regex mean. Also, have a look at rexegg.com. Commented Oct 27, 2016 at 11:19
  • wiktor -- thanks for your effort I will do. Commented Oct 27, 2016 at 11:22
  • Well, regexone.com will do for a start :) Commented Oct 27, 2016 at 11:22

1 Answer 1

2

You can easily use String.prototype.match() that select specific part of string by regex. Note that the \w+ matches word characters.

var str =  "  (  [Field1]  +  [Field2]  )    +    (  [Field3]  -  [Field4]  )  ";
var result = str.match(/\w+/g);
console.log(result);

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.