Possible Duplicate:
Regular Expression to find a string included between two characters, while EXCLUDING the delimiters
i have a function where i have to get text which is enclosed in square brackets but not brackets for example
this is [test] line i [want] text [inside] square [brackets]
from the above line i want words
test
want
inside
brackets
i am trying with to do this with /\[(.*?)\]/g
but i am not getting satisfied result i get the words inside brackets but also brackets which are not what i want
i did search for some similar type of question on SO but none of those solution work properly for me here is one what found (?<=\[)[^]]+(?=\])
this works in RegEx coach but not with javascript . Here is refrence from where i got this
here is what i have done so far demo
please help
A single lookahead should do the trick here:
but in a general case,
exec
orreplace
-based loops lead to simpler code:This fiddle uses RegExp.exec and outputs only what's inside the parenthesis.