我需要一个Perl脚本转换为VB.NET。我已成功几乎整个转换,但一些Perl的(貌似简单)的正则表达式是引起头痛。有人建议我.NET相当于下面的Perl的正则表达式的:
I need to convert a Perl script to VB.NET. I have managed almost the entire conversion, but some Perl (seemingly simple) regex are causing an headache. Can someone suggest me .NET equivalent of the following perl regex:
1)
$letter =~ s/Users //,;
$letter =~ s/Mailboxes //,;
if($letter =~ m/$first_char/i){
2)
unless($storegroup =~ /Recovery/ || $storegroup =~ /Users U V W X Y Z/ || $storegroup =~ /Users S T/
|| $storegroup =~ /Users Q R/){
正则表达式看起来简单给我。我试图涉水通过perl.org但了解一个langugae正则表达式需要一段时间,我需要尽快完成转换。
The regex look simple to me. I tried to wade through perl.org but understanding a langugae regex takes sometime and I need to complete the conversion quickly.
在Perl中,你能想到的斜线为类似双引号的这些斜线之间是一个正则表达式串的附加意义。的code中的第一个块是一个Perl查找/替换正则表达式:
In Perl, you can think of the slashes as something like double-quotes with the added meaning of "between these slashes is a regex-string". The first block of code is a Perl find/replace regex:
$stringvar =~ s/findregex/replaceregex/;
注意到 findregex
和 replaceregex
替换它,就地。给出的例子是一个非常简单的搜索,和.NET正则表达式类是杀鸡用牛刀。 与string.replace()
方法将做的工作:
Takes findregex
and replaces it with replaceregex
, in-place. The given example is a very simple search, and the .net Regex class would be overkill. String.Replace()
method will do the job:
letter = letter.Replace("Users ", "")
letter = letter.Replace("Mailboxes ", "")
第二部分是对的Perl只找到,返回真
如果发现findregex串,离开实际字符串本身不变。
The second part is Perl for find only, returns true
if the findregex string is found, leaves the actual string itself untouched.
$stringvar =~ /findregex/;
String.Contains()
可以处理这个在.NET:
String.Contains()
can handle this in .net:
if (!(storegroup.Contains("Recovery") _
or storegroup.Contains("Users U V W X Y Z") _
or storegroup.Contains("you get the idea"))) Then
...
(抱歉,如果我VB是有点生疏,但希望这有助于)
(sorry if my VB is a little rusty, but hope this helps)
上一篇:的WinForms:找到最小化形式的大小而不打算FormWindowState.Normal而不、最小化、形式、大小
下一篇:错误获取在Android窗口大小:"该方法getWindowManager是未定义"大小、窗口、错误、未定义