简体   繁体   English

带有空格的c样式字符串的regcomp表达式

[英]regcomp expression for c style string with white spaces

i am trying to detect an empty string or a string with just white spaces such as " ". 我试图检测一个空字符串或只有白色空格的字符串,如“”。 It is ac application and uses regcomp and regexec . 它是ac应用程序并使用regcompregexec

For empty string "^$" works fine. 对于空字符串"^$"工作正常。

But for string with just whitespaces i am getting a problem. 但对于只有空格的字符串,我遇到了问题。 So far, i have come up with 到目前为止,我已经提出了

"[\\\\s]*(?![A-za-z0-9])$"

Is there a better way to express it using perl style regular expression? 有没有更好的方法来表达它使用perl样式正则表达式?

UPDATE: i actually changed it "[\\\\s]*(?![\\\\w\\\\d\\\\t\\\\n\\\\r]*)$" 更新:我实际上改了它"[\\\\s]*(?![\\\\w\\\\d\\\\t\\\\n\\\\r]*)$"

The above gives an error when i give an input such as " m". 当我给出诸如“m”的输入时,上面给出了错误。 The error is 错误是

"Invalid preceding regular expression"

To test string for only white spaces, its Reg-Ex will be... 要仅测试白色空间的字符串,其Reg-Ex将...

^\\s*$

REF: helpful REF:乐于助人

How to test to see if a string is only whitespace in perl 如何测试以查看字符串是否只是perl中的空格

You should use * or + quantifier.. 你应该使用*+量词..

So it should be ^\\s*$ or ^ *$ 所以它应该是^\\s*$^ *$

* matches 0 to many characters *匹配0到多个字符

+ matches 1 to many characters +匹配1到多个字符

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM