如何在正则表达式中跳过引用的文本(或如何在Unicode文本中使用Hy
|
我需要正则表达式帮助创建一个delphi函数来替换Rad Studio XE2中的HyperString ParseWord函数. HyperString是一个非常有用的字符串库,从未跳转到Unicode.我得到它主要工作,但它根本不尊重引用分隔符.我需要它与下面描述的功能完全匹配:
这是我到目前为止: function ParseWord( const Source,Table: String; var Index: Integer):string;
var
RE : TRegEx;
match : TMatch;
Table2,chars : string;
begin
if index = length(Source) then
begin
result:= '';
exit;
end;
// escape the special characters and wrap in a Group
Table2 :='['+TRegEx.Escape(Table,false)+']';
RE := TRegEx.create(Table2);
match := RE.Match(Source,Index);
if match.success then
begin
result := copy( Source,Index,match.Index - Index);
Index := match.Index+match.Length;
end
else
begin
result := copy(Source,length(Source)-Index+1);
Index := length(Source);
end;
end;
while ( Length(result)= 0) and (Index<length(Source)) do
begin
Inc(Index);
result := ParseWord(Source,Table,Index);
end;
欢呼和谢谢. 解决方法
我会为Table2尝试这个正则表达式:
Table2 := '''[^'']+''|"[^"]+"|[^' + TRegEx.Escape(Table,false) + ']+'; 演示: >分隔符是空格(ASCII代码32)和管道(ASCII代码124)字符.
?? 讨论: 正则表达式将匹配: >单引号字符串 已知错误: 例如 : >如何解释这个’foo”bar’? =>两个令牌:’foo’和’bar’或一个令牌’foo”bar’.>这个案子呢:“foo”“bar”? =>两个令牌:“foo”和“bar”或一个令牌“foo”“bar”. (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
- The reference to entity "characterEncodin
- React 常见的面试题(在 React 里面,你可以知道
- Flex 接收外部参数
- 如何将XML数据转换为data.frame?
- XML文档定义有几种形式?解析XML文档有哪几种方式
- ruby – `(a || = [])<< 1`与`(i || = 0)= 1`
- Cocos2D-x 入门(2) win7(64)+VS2013+cocos2d-x 3
- 今天发现listings包的跨页问题(2014-3-26)
- ruby-on-rails – 使用Mongoid 3在mongodb中存储
- postgresql – 从具有OUT参数的函数返回
