JoshDG
JoshDG

Reputation: 3931

Regex: Match NOT curved or square bracket

This isn't matching. I want to match a string of characters that are not ] or ).

I used this regular expression, but it isn't matching '[^\\)\\]]+'

I'm sure its simple, but, help please :)

Working in R:

gsub('[\\(\\[]{1}[^\\)\\]]+[\\)\\]]{1}','','JOSH [IS MY NAME]')

Does not match anything. I want it to remove the data between the square brackets.

Upvotes: 2

Views: 3632

Answers (2)

JoshDG
JoshDG

Reputation: 3931

AH. I had to set perl=TRUE argument and it worked. All better thanks guys!

Upvotes: 1

Anirudha
Anirudha

Reputation: 32807

The regex would be

\\[[^\\[\\]]+\\]

This would replace anything within brackets..replace it with []

Upvotes: 2

Related Questions