本文介绍了使用正则表达式(正则表达式)在方括号内获取文本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想替换 String ,如下所示: [TEST] [QUESTION]

A文字在两个方括号之间



我尝试过:



我试图用这种模式正则表达式 [\ [] [A-Z0-9] [\]]

但这种模式只能得到这样的字符串: [A],[B],[C],[1]

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]

推荐答案

\[[A-Z0-9]+\]



或:


Or:

\[\w+\]



或者,如果你想匹配除方括号外的任何内容,请使用:


Alternatively, if you want to match anything except a square bracket, use:

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



[]




这篇关于使用正则表达式(正则表达式)在方括号内获取文本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-29 13:12
查看更多