|
例子:颜色:粉色[10] 尺码:S[5]6 b1 ~0 x* S: t; p( ?/ y
去掉[ ]及内容:
% i6 L; u5 @. _6 L0 v) C( ~& Y" l
6 w8 B1 N/ i8 e, bpreg_replace("/\[.*\]/", '', $str)1
" J& ?+ x! ~; {处理后效果:颜色:粉色 尺码:S
7 H9 X! \7 w# Y& |$ _. h$ b8 x R' H小技巧:可把[ ]改为其他符号应用在需要的地方
# J; \8 c$ }! D) T5 u Sps:下面看下利用正则表达式提取括号内内容
; w/ D5 D! {6 V: R7 E! [7 U比如现在要提取 中华人们共和国,简称(中国) 这句话中括号里的“中国”4 x, X: g8 x3 X3 ]& h; |
[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("(? |
|