正则表达式开始用[和结尾] [英] RegEx Starts with [ and ending with ]

查看:137
本文介绍了正则表达式开始用[和结尾]的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

什么是找到以[和结尾]字符串的正则表达式。之间[和]所有样的性格都很好。

What is the Regular Expression to find the strings starting with [ and ending with ]. Between [ and] all kind of character are fine.

推荐答案

[] 是在正则表达式的特殊字符,所以你需要躲避他们。这应该为你工作:[*?\]

[ and ] are special characters in regular expressions, so you need to escape them. This should work for you:

\[.*?\]

。*?做任何字符的非贪婪匹配。非贪婪的方面保证,你将匹配 [ABC] 而不是的[ABC]高清] 。添加一个领先的 ^ 和尾随 $ 如果要匹配整个字符串,例如没有比赛在所有 ABC [高清] GHI

.*? does non-greedy matching of any character. The non-greedy aspect assures that you will match [abc] instead of [abc]def]. Add a leading ^ and trailing $ if you want to match the entire string, e.g. no match at all in abc[def]ghi.

这篇关于正则表达式开始用[和结尾]的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆