Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

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

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
213 views
Welcome To Ask or Share your Answers For Others

1 Answer

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

[.*?]

.*? 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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...