简体   繁体   English

正则表达式匹配不在引号或转义引号中的字符

[英]Regex match for character not in quotes or escaped quotes

Hi I'm trying to write a regex statement to match a " { " character only if it is not in cased in quotes. 嗨,我正在尝试编写一个正则表达式语句,以仅在不加引号的情况下匹配“ { ”字符。

I then need to return (replace line) with everything (if anything) to the right of the character. 然后,我需要返回所有字符(如果有的话)到字符右边的(替换行)。

Similarly I need to do the same with the " } " character but return everything on the left. 同样,我需要对“ } ”字符执行相同的操作,但返回左侧的所有内容。 These need to be separate regex. 这些需要是单独的正则表达式。

As an example: 举个例子:

if { something

Should MATCH and return " something " 应该匹配并返回“ something

if { " something

Should MATCH and return " " something " 应该匹配并返回“ " something

" if { " something

Should NOT MATCH and not return anything 不应该匹配也不返回任何东西

Unfortunately this isn't something the .Net implementation of regex can do without running into edge cases. 不幸的是,.net实现regex不能在不遇到极端情况的情况下实现。 You'll need to use a parser to do it properly. 您将需要使用解析器来正确执行此操作。 A basic state machine pattern where that iterates along the string and flips state when it hits the characters you're looking for. 一种基本的状态机模式,该模式沿字符串迭代并在遇到所需字符时翻转状态。

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

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