正则表达式包括括号和排除空格

时间:2017-06-12 07:07:11

标签: regex

正则表达式,方法名称只包含一个开头和一个右括号,不接受任何空格。我试过了 -

(((。)))+

但它也接受了空格

2 个答案:

答案 0 :(得分:-1)

请举几个示例,但您的主要问题似乎是要排除\ s和括号。这可能意味着你需要

\([^\s\(\)]*\)

根据regex101.com(https://regex101.com/r/ZtMNbO/1)说明:

\([^\s\(\)]*\) \( matches the character ( literally (case sensitive) Match a single character not present in the list below [^\s\(\)]* * Quantifier — Matches between zero and unlimited times, as many times as possible, giving back as needed (greedy) \s matches any whitespace character (equal to [\r\n\t\f\v ]) \( matches the character ( literally (case sensitive) \) matches the character ) literally (case sensitive) \) matches the character ) literally (case sensitive)

或非常长的字符排除数组

我的建议已经给出了:

string * match

example() * ()
example(a) * (a)
example(a,a) * (a,a)
example(a, a) * no match
example(a(a)) * (a)

答案 1 :(得分:-1)

^\s - 将省略空格 在'('和')'前面使用\包含,因为两者都保留,所以你需要' \'提到它的匹配角色。

\(^\s\)