开发者

Java RegEx Question?

开发者 https://www.devze.com 2023-03-09 08:28 出处:网络
I have a problem with RegEx in java; my line is : CREATE CHAN:NAME=BTSM:1/BTS:2/TRX:5/CHAN:7,CHTYPE=TCHF_HLF,FHSYID=FHSY_0

I have a problem with RegEx in java;

my line is :

CREATE CHAN:NAME=BTSM:1/BTS:2/TRX:5/CHAN:7,CHTYPE=TCHF_HLF,FHSYID=FHSY_0

and I want this :

content [0] = BTSM:1/BTS:2/TRX:5/CHAN:7
content [1] = CHTYPE
content [2] = TCHF_HLF
content [3] = FHSYID
co开发者_StackOverflowntent [4] = FHSY_0

I wrote this :

String[] content = value.split("^=/:|,|=|,$");

but it's not work :( so kindly inform me about that... Thanks a lot ...


String[] content = value.replaceFirst("^[^=]*=", "").split("[,=]");

should do what you want.

I don't understand how you derived "^=/:|,|=|,$" so I can't tell you where you went wrong, but here's a breakdown of what it does.

^=/:

This is going to skip the string =/: if it occurs at the beginning and stick an empty string at the start of the results. Perhaps you wanted a character set. [=/:] is a character set that matches any occurence of one of those characters.

,

This will split on any comma.

=

This will split on any equals sign.

,$

This will skip a comma at the end of the input (or just before a newline at the end of input) and if skipped will stick an empty string on the end of the split result.


I don't know what the Hell that thing you're passing to split() is, but what you need to do is to split on any occurence of , or = after removing everything up through the first =. This can be accomplished with:

String[] content = (value.substring(value.indexOf('=') + 1)).split("[,=]");
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号