如何匹配除空格和新行之外的任何内容? [英] How to matches anything except space and new line?
本文介绍了如何匹配除空格和新行之外的任何内容?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个字符串,我只想匹配除空格和新行之外的任何字符的字符串.什么必须是正则表达式?
I have a string, I just want to match string for any character except for space and new line. What must be regular expression for this?
我知道除空格以外的任何正则表达式,即 [^ ]+
和除新行 [^\n]+
以外的任何正则表达式(我在 Windows 上)).我不知道如何将他们聚集在一起.
I know regular expressions for anything but space i.e. [^ ]+
and regular expression for anything but new line [^\n]+
(I'm on Windows). I am not able to figure how to club them together.
推荐答案
您可以将空格字符添加到要排除的字符类中.
You can add the space character to your character class to be excluded.
^[^\n ]*$
正则表达式
^ # the beginning of the string
[^\n ]* # any character except: '\n' (newline), ' ' (0 or more times)
$ # before an optional \n, and the end of the string
这篇关于如何匹配除空格和新行之外的任何内容?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文