Differences between revisions 6 and 7
Revision 6 as of 2007-02-27 17:21:23
Size: 1685
Editor: KaiJaeger
Comment:
Revision 7 as of 2007-06-25 08:05:30
Size: 1699
Editor: KaiJaeger
Comment:
Deletions are marked like this. Additions are marked like this.
Line 1: Line 1:
.Net comes with build-in regular expression. Here some useful functions are implement. One is checking an email address for being valid, the other one takes a url and returns "{!ProtocolName}:{!PortNo}" as a result. .Net comes with build-in regular expression. Here some potentially useful functions are implemented. One is checking an email address for being valid, the other one takes a url and returns "{!ProtocolName}:{!PortNo}" as a result.

.Net comes with build-in regular expression. Here some potentially useful functions are implemented. One is checking an email address for being valid, the other one takes a url and returns "{ProtocolName}:{PortNo}" as a result.

The examples are taken from the C# help file Visual Studio Express comes with. The changes needed to make them work under Dyalog APL/W are not a big deal.

r←IsValidEmailAddr emailAdr;regPattern
⍝⍝ Returns 1 if the string contains a
⍝⍝ valid email address, otherwise 0
 ⎕ML ⎕IO←1
 ⎕USING,←⊂''
 regPattern←'^([\w-\.]+)@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.)|(([\w-]+\.)+))([a-zA-Z]{2,4}|[0-9]{1,3})(\]?)$'
 r←System.Text.RegularExpressions.Regex.IsMatch(emailAdr regPattern)

{{{TestEmailAddr;msg

}}}

returns

Is fine: ...

Is NOT fine: ...

Is NOT fine: ...

r←ProtocolAndPortFrom url;regPattern;q
⍝⍝ The following code example uses Match.Result to extract a protocol and port number from a URL
⍝⍝ For example, "http://www.contoso.com:8080/letters/readme.html" would return "http:8080".

 ⎕ML ⎕IO←1
 ⎕USING,←⊂''
 regPattern←'^(?<proto>\w+)://[^/]+?(?<port>:\d+)?/'
 r←(System.Text.RegularExpressions.Regex.Match(url regPattern)).Result⊂'${proto}${port}'

TestProtocolAndPort
 ⎕←ProtocolAndPortFrom'http://www.contoso.com:8080/letters/readme.html'

returns

http:8080

Author: Kai Jaeger


CategoryDyalogExamplesDotNet

RegularExpressionsWithDyalogAndDotNet (last edited 2015-04-05 01:25:27 by PierreGilbert)