|
|
例子:颜色:粉色[10] 尺码:S[5]
8 E( r9 s0 T0 u& i6 k3 A去掉[ ]及内容:
5 Y( B0 d: O" f; S6 W3 Z
9 s! J* l6 _4 V# ypreg_replace("/\[.*\]/", '', $str)18 w. }6 ~6 d, j+ g) X6 I
处理后效果:颜色:粉色 尺码:S! E1 o8 S# w8 w0 a B
小技巧:可把[ ]改为其他符号应用在需要的地方
' V6 O9 J% M4 e# G; C& zps:下面看下利用正则表达式提取括号内内容 $ \3 `4 r$ I0 N
比如现在要提取 中华人们共和国,简称(中国) 这句话中括号里的“中国”
% M" J7 t3 X' p3 U# E# B[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("(? |
|