VB6 and C# regexes

落爺英雄遲暮 提交于 2019-12-05 13:23:22

The old VB Like operator, despite appearances, is not a regular expression interface. It's more of a glob pattern matcher. See http://msdn.microsoft.com/en-us/library/swf8kaxw.aspx

In your example:

Like "*[!0-9A-Z]*"

Matches strings that start and end with any character (zero or more), then doesn't match an alphanumeric character somewhere in the middle. The regular expression for this would be:

/.*[^0-9A-Z].*/

EDIT To answer your question: No, the two can't be used interchangeably. However, it's fairly easy to convert Like's operand into a proper regular expression:

Like       RegEx
========== ==========
?          .
*          .*
#          \d
[abc0-9]   [abc0-9]
[!abc0-9]  [^abc0-9]

There are a few caveats to this, but that should get you started and cover most cases.

In a word, yes.

These are the same. Some quick googling should give you answers to more complex issues.

http://social.msdn.microsoft.com/Forums/en-US/csharpgeneral/thread/bce145b8-95d4-4be4-8b07-e8adee7286f1/

http://www.regular-expressions.info/dotnet.html

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!