我怎样写一个正则表达式匹配不包含一个字一个字符串? [英] How do I write a regex to match a string that doesn't contain a word?

查看:231
本文介绍了我怎样写一个正则表达式匹配不包含一个字一个字符串?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

可能重复:结果
正则表达式匹配不包含字串?

要不匹配一组字符,我会用如的 [^ \\\r\\\\
] *

To not match a set of characters I would use e.g. [^\"\\r\\n]*

现在我想不匹配的固定字符集,例如| =

Now I want to not match a fixed character set, e.g. "|="

在换句话说,我想匹配:(不是,不\r,不\\\
,和。不| =)

In other words, I want to match: ( not ", not \r, not \n, and not |= ).

编辑:我想修改解析用分隔符分隔数据正则表达式。单分隔符的解决方案我得到了形式一个CSV解析器,但现在我想它扩大到包括多字符分隔符。我不认为向前看符号会的工作,因为我要消费,而不仅仅是维护和丢弃,匹配的字符。

I am trying to modify the regex for parsing data separated with delimiters. The single-delimiter solution I got form a CSV parser, but now I want to expand it to include multi-character delimiters. I do not think lookaheads will work, because I want to consume, not just assert and discard, the matching characters.

推荐答案

我理解了它,它应该是:(?!([\\\r\\\\
] | [|] [=]))*

I figured it out, it should be: ((?![\"\\r\\n]|[|][=]).)*

完整的正则表达式,在原岗位从CSV解析器链接修改为:((小于场>((? ![\\\r\\\\
] | [|] [=]))*)| \。(小于字段>([^ \] | \\\ \\)*)\)([|] [=] |(小于rowbreak> \\r\\\\
| \\\\
| $))

The full regex, modified from the CSV parser link in the original post, will be: ((?<field>((?![\"\\r\\n]|[|][=]).)*)|\"(?<field>([^\"]|\"\")*)\")([|][=]|(?<rowbreak>\\r\\n|\\n|$))

这将匹配任何字符数量(不,不是\r,不\\\
,而不是| =),或带引号的字符串,然后是(| =或行尾)

This will match any amount of characters of ( not ", not \r, not \n, and not |= ), or a quoted string, followed by ( "|=" or end of line )

这篇关于我怎样写一个正则表达式匹配不包含一个字一个字符串?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆