且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

正则表达式,grep行仅包含1个字符

更新时间:2022-05-20 22:39:02

尽管@Rawling(这里的答案之一)是正确的,并且他的正则表达式是正确的,但它仍然没有占有欲,因此没有进行优化,但他是正确的不会发生回溯,但是它不会具有***性能,因为所有格量词不必记住任何回溯位置.如问题所附链接中所述.

Although @Rawling (one of the answers here) is right and his regular expression is correct, it is still not possessive and therefore not optimized, he is correct that no backtracking will occur, but it will not be with the best performance because the possessive quantifier doesn't have to remember any backtracking positions. as was mentioned in the link attached in the question.

下面的表达式将是所有格和优化的,我将按照问题中的要求与grep一起使用进行演示:

The following expression will be possessive and optimized, i will demonstrate together with the use of grep as was asked in the question:

grep -E"^ [^,] * +,[^,] * + $"大数据

grep -E "^[^,]*+,[^,]*+$" big_data