Java 正则表达式问题?
我在 java 中遇到 RegEx 问题;
我的台词是:
CREATE CHAN:NAME=BTSM:1/BTS:2/TRX:5/CHAN:7,CHTYPE=TCHF_HLF,FHSYID=FHSY_0
我想要这个:
content [0] = BTSM:1/BTS:2/TRX:5/CHAN:7
content [1] = CHTYPE
content [2] = TCHF_HLF
content [3] = FHSYID
content [4] = FHSY_0
我写了这个:
String[] content = value.split("^=/:|,|=|,$");
但这不起作用:( 请告诉我这件事...... 多谢 ...
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
content [4] = FHSY_0
I wrote this :
String[] content = value.split("^=/:|,|=|,$");
but it's not work :(
so kindly inform me about that...
Thanks a lot ...
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
应该做你想做的事。
我不明白你是如何推导
"^=/:|,|=|,$"
所以我无法告诉你哪里出了问题,但这里是它的作用的细分。如果字符串
=/:
出现在开头,则会跳过它,并在结果的开头粘贴一个空字符串。也许您想要一个字符集。[=/:]
是匹配这些字符之一的任何出现的字符集。这将在任何逗号上分开。
这将在任何等号上分开。
这将跳过输入末尾的逗号(或输入末尾的换行符之前),如果跳过,将在分割结果的末尾粘贴一个空字符串。
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.
我不知道你传递给 split() 的东西到底是什么,但你需要做的是在任何出现
、
或 < 的情况下进行拆分删除第一个=
之前的所有内容后。这可以通过以下方式完成: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: