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

Mohammad
  • 21,175
  • 15
  • 55
  • 84
Ksm
  • 91
  • 11
  • 1
    So, tried some basic regex yet? – Wiktor Stribiżew Oct 27 '16 at 11:12
  • Wiktor Stribiżew I will start to learn regex. thanks – Ksm Oct 27 '16 at 11:17
  • Starting to learn by doing nothing will not help. Do all lessons at [regexone.com](http://regexone.com/), read through [regular-expressions.info](http://www.regular-expressions.info), [regex SO tag description](http://stackoverflow.com/tags/regex/info) (with many other links to great online resources), and the community SO post called [What does the regex mean](http://stackoverflow.com/questions/22937618/reference-what-does-this-regex-mean). Also, have a look at [rexegg.com](http://rexegg.com). – Wiktor Stribiżew Oct 27 '16 at 11:19
  • wiktor -- thanks for your effort I will do. – Ksm Oct 27 '16 at 11:22
  • Well, regexone.com will do for a start :) – Wiktor Stribiżew Oct 27 '16 at 11:22

1 Answers1

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);
Mohammad
  • 21,175
  • 15
  • 55
  • 84