説明
この正規表現は、N、S、E、W の後に空白と追加のテキストまたは行末が続く通りのみに一致します。
^([nsew])\b(?:\s.*?)?$
例
言語を指定しなかったので、PHP を選択して正規表現のデモを行いました。
<?php
$sourcestring="N Wisconsin Drive
S Voter Booth
E Kitten Ave
W Washington Street
Noghtington Lane
Silver Stone Drive
Edans Expressway
Wireware Waythrough";
Dim re As Regex = New Regex("^([nsew])\b(?:\s.*?)?$",RegexOptions.IgnoreCase OR RegexOptions.Multiline)
Dim mc as MatchCollection = re.Matches(sourcestring)
Dim mIdx as Integer = 0
For each m as Match in mc
For groupIdx As Integer = 0 To m.Groups.Count - 1
Console.WriteLine("[{0}][{1}] = {2}", mIdx, re.GetGroupNames(groupIdx), m.Groups(groupIdx).Value)
Next
mIdx=mIdx+1
Next
End Sub
End Module
$matches Array:
(
[0] => Array
(
[0] => N Wisconsin Drive
[1] => S Voter Booth
[2] => E Kitten Ave
[3] => W Washington Street
)
[1] => Array
(
[0] => N
[1] => S
[2] => E
[3] => W
)
)