User254389092 posted
Hi,
I have a typical issue. I need a C# regular expression that validates file paths, FQDN, IP addresses. I have tried the following:
^\\(\\[\w-\.]){1,}(\\[\w-()](\s[\w-()]))(\\(([\w-()](\s[\w-()]))\.[\w])?)?$ - Initial test
^.{4,253}$)(^((?!-)[a-zA-Z0-9-]{0,62}[a-zA-Z0-9]\.)+[a-zA-Z]{2,63}$) - works for FQDNs of any kind but fails file paths.
^(?:[a-zA-Z]\:|\\\\[\w\.]+\\[\w.$]+)\\(?:[\w]+\\)*\w([\w.])+$
- Current trial but fails.
I tried online where I can find individual regular expressions but not something that works for all three. The examples I need to satisfy are HTTP://<my test path>
c:\Dev\temp.doc
In my code, the implementation will be as:
[LocalizedRegularExpression(@"(?=^.{4,253}$)(^((?!-)[a-zA-Z0-9-]{0,62}[a-zA-Z0-9]\.)+[a-zA-Z]{2,63}$)", "Path_issue")]
I need to replace the path above.
As an update:
(?=^.{4,253}$)(^((?!-)[a-zA-Z0-9]{0,62}[a-zA-Z0-9]\.)+[a-zA-Z0-9]{2,63}$) - This helps for URL without http:// or https:// and IP addresses.
I am looking for http:// or https:// and file path types in this as well.
I appreciate any help.
Luc