我想要计算包含特定ID(例如* AUY)的特定行中的字数。到目前为止,我已经使用下面的正则表达式查找行了尝试,但它并没有考虑“*”在开始计算以特定字开头的行中的字数
^ *(.*\b(?:\\*AUY)\b.*) *$
我有以下测试字符串
*AUY: today is holiday so Peter and Mary do not need to go to work .
%mor: n|today cop|be&3s n|holiday conj|so n:prop|Peter conj|and n:prop|Mary v|do neg|not v|need inf|to v|go prep|to n|work .
%snd: <00:00:00><00:07:37>
%AUY: ok_pfp (0.40) er today is holiday errfr ::: so er Peter and Mary {is} ~ er do not need errfr ::: to go to work . errfr :;:a |
结果应该只有第一字符串,但它返回结果匹配中的首个和最后一个字符串 看到这个Rubular
你能让你的问题更清楚吗?你想从你提供的测试字符串中提取什么? – MYGz
你可以'string.split('').length' – Rajesh
你的脚本现在只是(尝试)匹配字符串,但不包括单词。所有你需要匹配的字符串是'^ \ * AUY。*'。这是你要找的所有东西吗?你试过什么代码*计数*字符串中的单词数量? –