[英]Splitting complicated string with regex
I have very basic knowledge of regular expressions and this one is just too hard for me. 我对正则表达式非常了解,这一点对我来说太难了。 I need to split string into three parts.
我需要将字符串分成三部分。
My input looks like this XXX YYY:ZZZ:
(always ends with :ZZZ:
) 我的输入看起来像这样
XXX YYY:ZZZ:
总是以:ZZZ:
结尾)
$&+,:;=?@#|'<>.-^*()%!
$&+,:;=?@#|'<>.-^*()%!
and spaces .
.
or are not there at all :
at the end of string :
在字符串的末尾 Trickiest string I can come up with is Lo-rem ip sum.,::0001678154:
. 我能想到的最棘手的字符串是
Lo-rem ip sum.,::0001678154:
ZZZ
would be 0001678154
we can get rid off :ZZZ:
so remaining part is Lo-rem ip sum.,:
but last char is not either alphanumeric or .
ZZZ
为0001678154
我们可以摆脱:ZZZ:
0001678154
所以剩余部分是Lo-rem ip sum.,:
但最后一个字符不是字母数字或.
so that means YYY is not included in this string XXX
is whatever remained ( Lo-rem ip sum.,:
) 因此,表示此字符串中不包括YYY
XXX
就是剩下的值( Lo-rem ip sum.,:
Now I have horrible half functioning code with hardcoded lengths, ifs, substrings and splits I believe you could come up with better solution. 现在,我有了具有硬编码长度,if,子字符串和拆分的可怕的半功能代码,我相信您可以提供更好的解决方案。 Thanks
谢谢
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.