不跟随特定字符(?)时如何使用正则表达式匹配字符(')? [英] How can I use regex to match a character (') when not following a specific character (?)?
问题描述
只要不带问号,我如何编写正则表达式模式以使用特定的分隔符来分割字符串?
How can I write a regex pattern to split a string by a specific delimiter as long as it's not preceded by a question mark?
我编写了一个解析器,将EDIFACT消息拆分为段,组合和元素.但是在EDI标准中,问号是转义字符.因此,请分割此字符串:
I've written a parser that splits an EDIFACT message into segments, composites and elements. But in the EDI standard the question mark is an escape character. So to split this string:
'PRI+2.005:1+9022.5'RAD+RRHANB97+120814'
我可以使用string.Split('\''),然后使用string.split('+'),然后使用string.split(':')获得PRI,2.005、1、9022.5,依此类推但是,这些字符可以用问号转义:
I can use string.Split('\''), and then string.split('+') and then string.split(':') to get PRI, 2.005, 1, 9022.5 and so on However, these characters can be escaped by a question mark:
'PRI+2.005?+3.2:1+9022.5'RAD?'R+RRHANB97+120814'
现在应该是PRI,2.005 + 3.2、1、9022.5,RAD'R,RRHANB97.
which should now be PRI, 2.005+3.2, 1, 9022.5, RAD'R, RRHANB97.
有人可以帮助匹配'而不是'的正则表达式吗?
Can someone help with a regular expression that would match the ' and not the ?'?
谢谢
推荐答案
使用后向负向:
(?<!\?)'
这篇关于不跟随特定字符(?)时如何使用正则表达式匹配字符(')?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!