Regular expressions are undoubtedly a very powerful tool for text processing. But writing and reading regular expressions is often not a very pleasant thing to do. This article introduces another kind of alternative regular expression--verbalexpressions, it uses the function chain to realize the expression of a turn colloquial, also can be very convenient similar to the regular expression string matching function.
1 [TestMethod]2 Public voidTestingifwehaveavalidurl ()3 {4 //Create An example by how to test for correctly formed URLs5 varVerbex =Newverbalexpressions ()6 . StartOfLine ()7. Then ("http" )8. Maybe ("s" )9. Then ("://" )Ten. Maybe ("www." ) One. Anythingbut (" " ) A . EndOfLine (); - - //Create An example URL the varTestme ="https://www.google.com"; - -Assert.istrue (Verbex.test (Testme),"The URL is incorrect"); - +Console.WriteLine ("We have a correct URL"); -}
It is also available in a variety of other languages and can be viewed on its homepage.
As can be seen from the above example, it is very easy to read and the learning threshold is relatively low. Of course, its use of the scope and function should be less than the regular expression so powerful. While I think regular expressions are a must-have for programmers, at some point these easy-to-read expressions are a good choice.
verbalexpressions--Alternative Regular Expressions