Click here to Skip to main content
15,883,705 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hi , I want to replace String that is like this : [TEST] [QUESTION]
A text is between two Square Brackets

What I have tried:

I tried to use Regex with this pattern : [\[][A-Z0-9][\]]
But this pattern only get strings like this : [A], [B], [C], [1]
Posted
Updated 18-Jul-16 7:19am
v3

You're only looking for a single character. You need to expand your pattern to match multiple characters:
\[[A-Z0-9]+\]

Or:
\[\w+\]

Alternatively, if you want to match anything except a square bracket, use:
\[[^\[\]]+\]

Regular Expression Language - Quick Reference[^]
 
Share this answer
 
v2
Links to help debug RegEx:
Debuggex: Online visual regex tester. JavaScript, Python, and PCRE.[^], here, you see your RegEx as a diagram , it is helpful to understand where is a problem
.NET Regex Tester - Regex Storm[^]
 
Share this answer
 
Just Used : [\[A-Z0-9\]] And Worked
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900