0

I have RegEx that I believe should work, but isn't.

I would like to grab 'test' out of [[test]].

I have tried:

\[\[(\w+)\]\]
\[\[([A-z]*?)\]\]
\[\[(.*?)\]\]

All of which just grab the whole thing. Meaning, it grabs [[test]], instead of just the content. I am unsure how to get a regex that will grab JUST 'test' and not the brackets.

user2767260
  • 283
  • 2
  • 10
  • I would recommend looking at this related question: http://stackoverflow.com/questions/4026685/regex-to-get-text-between-two-characters –  Sep 11 '13 at 04:38
  • Reading this right now! – user2767260 Sep 11 '13 at 04:44
  • What language are you using? If it's C# you `do` have to escape the brackets – jmstoker Sep 11 '13 at 04:44
  • I am using Racket's regexp. But, I am testing this all with regexpal.com, and can not for the life of me come up with a solution that doesn't include the brackets with it. It seems to simple, yet it isn't. – user2767260 Sep 11 '13 at 04:48
  • What's the ultimate purpose of the regex? Just find some text or do you want to find it and replace the brackets? – jmstoker Sep 11 '13 at 04:53
  • Ultimate purpose is to grab text from between beginning and ending double brackets. Which doesn't require double brackets being in my regex at all... – user2767260 Sep 11 '13 at 04:59

2 Answers2

0

you must remove the backslashes. brackets don't need to be escaped and you can group parts of the pattern expression enclosing them with "(" and ")":

[[\(\w\w*\)]]

or

\[\[\([A-z][A-z]*\)\]\]

or

\[\[[A-z][A-z]*\]\]

will work correctly.

orezvani
  • 3,595
  • 8
  • 43
  • 57
0

What about this ?

\[\[(.+)\]\]

It might be a good idea to specify which language you are using. That will determine of you need to escape the brackets.

this worked on http://regexpal.com/ it will simply match the word characters if that is all you need.

\w+
Roman
  • 16
  • 3
  • This is still grabbing both brackets from the beginning and end – user2767260 Sep 11 '13 at 04:44
  • This does work! Thank you. For some reason I kept trying to use [[ before the part I wanted to grab (which is always word characters) and couldn't get that to work. Was making it more complicated than it needed to be. – user2767260 Sep 11 '13 at 04:58