AX本身不支持regular expression,但可以使用.Net 的Regular Expression。
链接是一个很好的demo。
http://fourone.se/blog/2009/10/02/using-regular-expressions-in-dynamics-ax/
链接是Regular Expression语法
https://dotblogs.com.tw/johnny/archive/2010/01/25/13301.aspx
代码如下:
Static Server boolean validateEmail(EMail _eMail)
{
Str MatchEmailPattern =
@"^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,4}$";
System.Text.RegularExpressions.Match myMatch;
;
myMatch = System.Text.RegularExpressions.Regex::Match(
_eMail, MatchEmailPattern);
return(myMatch.get_Success());
}
static void Job1(Args _args)
{
Str EmailPattern =
@"\b[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,4}\b";
Str ReplacedText;
;
ReplacedText =
System.Text.RegularExpressions.Regex::Replace(
"My email address is: rikky@haxx.net",
MatchEmailPattern,"harry@haxx.net");
print ReplacedText;
pause;
}
static void Job6(Args _args)
{
Str MatchEmailPattern =
@"\b[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,4}\b";
System.Text.RegularExpressions.Match myMatch;
;
myMatch = System.Text.RegularExpressions.Regex::Match(
"Your email: youremail@host.net, and my"
+"email: myemail@anotherhost.com", MatchEmailPattern);
while (myMatch.get_Success())
{
print myMatch.get_Value();
myMatch = myMatch.NextMatch();
}
pause;
}
网友评论