正则表达式 – perl分裂奇怪的行为
发布时间:2020-12-14 06:22:17 所属栏目:百科 来源:网络整理
导读:我提前道歉,这可能是一个非常愚蠢的问题,有一个显而易见的解决方案,它逃避了一个相当初学者的眼睛,或者它也可能已经在Stackoverflow中作为一个解决的问题,但我缺乏关于究竟是什么的知识寻找是阻止我实际找到答案. 我有一个字符串: $s = FOO: single blanksp
我提前道歉,这可能是一个非常愚蠢的问题,有一个显而易见的解决方案,它逃避了一个相当初学者的眼睛,或者它也可能已经在Stackoverflow中作为一个解决的问题,但我缺乏关于究竟是什么的知识寻找是阻止我实际找到答案.
我有一个字符串: $s = FOO: < single blankspace> BAR <some whitespace character> some more text with whitespace that can span over multiple lines,i.e. has n in them ; #please excuse the lack of quotes,and large text describing the character in angular brackets,but in this example,but I have the string correctly defined,and in plase of <blankspace> I have the actual ASCII 32 character etc. 现在我想以这种方式拆分$s: ($instType,$inst,$trailing) = split(/s*/,$s,3); #please note that i do not use the my keyword as it is not in a subroutine #but i tested with my,it does not change the behavior 我希望,$instType取值FOO :,没有任何周围的空间,在实际的测试字符串中有一个冒号,我相信,据我所知,它将保留在$instType中.然后很明显地期望$inst与BAR相似,然后最后也可以依靠$trail来获取其余的字符串. 但是,我得到了: 我该如何解决这个问题? PS perl是5.18.0
问题是量词*允许零空间(零或更多),你必须使用,这意味着1或更多.
请注意,F和O之间的空间正好为零. (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |