美文网首页
A Visual Approach to Learn Regul

A Visual Approach to Learn Regul

作者: WhiteWhite_iOS | 来源:发表于2019-07-08 21:27 被阅读0次

    Like many others, understanding regular expression was one of the most difficult things I ever had to do. I had to because as an iOS developer (an UI builder or sometimes just a button writer), regular expression is inevitable in cases like, say, you wanna make sure the user input you get is a valid email address. As a Google Oriented Programmer, I tried to search for helpful materials from the web, but what I got for "regular expression" was boring and tedious. Reading a long reference book before actually try a reg-ex pattern was frustrating. I was desperate for some quick examples to help me see the forest from the trees.

    像许多人一样,理解正则表达式的概念曾对我是一个大难题。作为一个iOS开发(UI开发或者写button的),正则在某些场景是必须要用的。比如,你想确定一个用户输入的内容是合法的email地址。同时,作为一个面向Google编程的开发者,我尝试从网上搜索学习正则的内容,但它们大多都是枯燥无聊的。要使用正则之前还得读很多材料,这种太难受了。当时的我非常需要几个快速的例子,让我找到一些对正则的感觉。

    Recently, inspired by the Dragon Book, I decided to invent a new wheel which can visually present how a regular expression matching is actually done. Thus the project RegSwift.

    最近,受龙书启发,我开发了一个工具来用视觉的方式展示正则匹配的过程。 RegSwift.

    RegSwift parses your input reg-ex patterns and internally creates an NFA. It then uses Graphviz to render the equivalent directed graph to an image. As you click the 'Evolve' button, nodes in orange would transit along the arrows to hint state transitions. Every time a 'fin'-prefixed state is hit, it indicates a match is found.

    RegSwfit将你输入的pattern解析成NFA。然后使用Graphviz将NFA绘制成相应的图片。之后每次点击Evolve按钮,状态节点都会沿箭头方向演进,展示状态转换的过程。每次有fin标识的状态被触达,则说明找到了一个匹配。

    RegSwift is an interactive tool, which shows you how NFAs and regular expressions work. It cost me several weekends so please star it if you like it, I really appreciate it. I don't mind if you star it more than once you have more github accounts. Many thanks!

    RegSwift是一个交互式的工具,它用视觉的方式告诉你NFA和正则的原理。我花了几个周末来开发这个工具。所以如果你喜欢这个repo,请start它。如果你有好几个github账号,都star一下我也不介意~ 多谢!

    https://github.com/White-White/RegSwift

    相关文章

      网友评论

          本文标题:A Visual Approach to Learn Regul

          本文链接:https://www.haomeiwen.com/subject/cnxzhctx.html