I am creating an application that saves named regular expressions to a database. Looks like that:
I am using Asp.Net forms. How can I check the entered regular expression? He would like the user to know that the regular expression entered is not a valid .Net regular expression.
The field should reject values ββsuch as:
^Wrong(R[g[x)]]$ Invalid\Q&\A
Extract the new Regex class from it. If it throws an exception, then it is invalid.
try{ new Regex(expression) } catch(ArgumentException ex) { // invalid regex } // valid regex
I know. Using exceptions for code logic is wrong. But this seems to be only a solution.
Something like this is possible:
public static class RegexUtils { public static bool TryParse (string possibleRegex, out Regex regex) { regex = null; try { regex = new Regex(possibleRegex); return true; } catch (ArgumentException ae) { return false; } } }
Source: https://habr.com/ru/post/1442286/More articles:Java returned type - javaCan I load JPA mappings from Java annotations and save them as XML? - javaPrevent an authorized user from editing data that does not belong to him - databaseAutoMapper Object Mapping - List Display - automapperCode Separation / Printing Format - Official Mentioned - javaHow can I open a drop-down list on the first touch, follow the link on the second - jQuery? - jqueryConnection failure on an asynchronous NIO2 Java7 server - javaCEF and localized strings in * .pak files - c ++How to add a sound alert for message notification in javascript? - javascriptNeed help (search algorithm) - algorithmAll Articles