|
|
例子:颜色:粉色[10] 尺码:S[5]
. q) i8 Y3 \7 S8 a, }. {0 I去掉[ ]及内容:
8 j8 l- T3 E4 L, |3 Y5 j
7 L9 P8 a4 t% T' Gpreg_replace("/\[.*\]/", '', $str)1
2 `/ {. j( M1 E, ]处理后效果:颜色:粉色 尺码:S
9 e5 G: {2 R X2 H( L+ r小技巧:可把[ ]改为其他符号应用在需要的地方7 z6 C+ _% o; h# `) v5 g
ps:下面看下利用正则表达式提取括号内内容
1 R# @+ I- F; w4 O比如现在要提取 中华人们共和国,简称(中国) 这句话中括号里的“中国”
6 ]: X- l. N8 V) o. c/ O[code]import java.util.regex.Matcher;import java.util.regex.Pattern;public class Test{ public static void main(String[] args) { String str ="中华人民共和国,简称(中国)。"; Matcher mat = Pattern.compile("(? |
|