[{"data":1,"prerenderedAt":439},["ShallowReactive",2],{"project-14731631":3},{"id":4,"name":5,"line":6,"line_source":7,"title":8,"url":9,"domain":10,"maker":11,"posted_at":12,"year":13,"points":14,"comments":15,"rank_in_year":16,"shown_in_year":17,"top":18,"tier":19,"category":20,"subcategory":21,"format":22,"keywords":23,"reception":28,"sentiment":29,"stance_mix":30,"scored_comments":35,"aspects":36,"strip":41,"post_text":43,"what":44,"said":88,"maker_in_thread":213,"shape":225,"grid":229,"attempts":357,"same_week":402,"maker_shows":32,"maker_hidden":431,"reader_version":432,"card":433},"14731631","crocs","Using functions to construct Regex in Python","title","Show HN: Using functions to construct Regex in Python","https:\u002F\u002Fgithub.com\u002Fiogf\u002Fcrocs","github.com","iogf",1499633972,2017,105,55,434,2242,20,"notable","dev_tools","regex builder","library",[24,25,21,26,27],"regex","python","parser combinator","regular expressions","mixed",-0.231,{"positive":31,"neutral":32,"mixed":33,"critical":34},4,7,1,9,21,{"idea":37,"design":38},{"positive":31,"critical":31},{"positive":39,"critical":40},0,5,[42,39,33,39,42,42,39,33,39,39,33,40,40,42,39,33,39,39,33,42,39,33,39,39,39,42,39,39,33,33,39,40,40,39,39,33,42,39,39,39],3,null,{"problem":45,"audience":60,"pricing":43,"motivation":71,"time_to_build":43,"stack":82,"openness":87,"stage":87,"team_size":87},{"value":46,"source":47,"evidence":48},"Regular expressions are hard to read, write and debug","commenter",[49,53,57],{"id":50,"by":51,"text":52},"14731735","gattilorenz","While the idea is very cool, it seems to have most of the drawbacks of traditional regexes (i.e. the little Syntax quirks that eventually one has to learn), with none of the…",{"id":54,"by":55,"text":56},"14731969","nemetroid","I find this: ``` mail = '(?P\u003Cname>[a-z][a-z0-1\\_\\.\\-]{1,})' hostname = '(?P\u003Chostname>python[a-z]{1,})' domain = '(?P\u003Cdomain>br[a-z])' match_mail = f'{mail}\\@{hostname}\\.{domain}'…",{"id":58,"by":11,"text":59},"14732094","The example is longer than the regex itself however it is simpler to explain to a beginner what crocs's example does than explaning the regex itself. Based on that assumption…",{"value":61,"source":62,"evidence":63},"Python programmers who write regular expressions","inferred",[64,68],{"id":65,"by":66,"text":67},"14731866","dizzystar","I agree with you. At some point, you are bound to get into situations where writing the regex is shorter and easier to do the normal way. Some the examples are getting a little…",{"id":69,"by":11,"text":70},"14732179","It can be ported to py3 with no difficult though it is meant to be used as a tool to construct regex, it shouldnt be put in your programs for a matter of performance at…",{"value":72,"source":73,"evidence":74},"Make regex construction more readable and easier to reason about","maker",[75,76,79],{"id":58,"by":11,"text":59},{"id":77,"by":11,"text":78},"14731949","The idea is having a set of entities on which one could reason better to implement more complex filters(regex) as well as debugging them. It is sort of a way of reasoning on…",{"id":80,"by":11,"text":81},"14732151","The main benefit about crocs it is purely epistemological in the sense it eases learning and consequently improves reasoning when implementing filters for content instead of…",[83],{"value":84,"source":47,"evidence":85},"Python",[86],{"id":65,"by":66,"text":67},"unknown",{"praise":89,"objections":112,"requests":146,"questions":168,"alternatives":184},[90,101],{"value":91,"source":47,"evidence":92},"Readable and easier to reason about than raw regex",[93,97],{"id":94,"by":95,"text":96},"14731794","pygy_","I have a similar lib in JS that uses either regexps or plain strings for the leafs, and combinators to implement the various regexp operators. It is useful for maintainability.…",{"id":98,"by":99,"text":100},"14734394","rajaravivarma_r","I always wanted to do something like this. Because I always forgot how to do the 'look ahead' assertions. I even named the library 'hu_regex', where 'hu' stands for human, but…",{"value":102,"source":47,"evidence":103},"Interesting idea similar to existing combinator libraries",[104,108],{"id":105,"by":106,"text":107},"14731798","Drup","Regex combinators are quite common in functional languages (where it works quite better than in python). One particular advantage compared to Regex syntax is that you stay inside…",{"id":109,"by":110,"text":111},"14731787","agumonkey","I always liked this idea (reminiscent of emacs rx dsl). But I'm not sure I'd be using it that often...",[113,124,131,139],{"value":114,"source":47,"evidence":115},"Harder to learn than standard regex syntax",[116,120],{"id":117,"by":118,"text":119},"14731889","matthberg","Really cool concept, yet not practical in my opinion. The classes and functions called to replace the regex I consider to be harder to learn than the initial regex. With regex…",{"id":121,"by":122,"text":123},"14731831","stonewhite","I don't really think this is more readable than the regex itself once it starts to get complex, like they all do. Maybe if this was implemented on a prefix notation language it…",{"value":125,"source":47,"evidence":126},"Debugging errors is hard since it delegates to Python re",[127],{"id":128,"by":129,"text":130},"14732358","reikonomusha","(Separate comment addressing the library itself.) I find the naming of the classes off. Why not call X as Any? Why use nouns for some things, and verbs for others? I found…",{"value":132,"source":47,"evidence":133},"Naming of classes is confusing (Include, Exclude, Seq, Times)",[134,135],{"id":128,"by":129,"text":130},{"id":136,"by":137,"text":138},"14735862","Asooka","I also think the naming is really bad and can be improved. The central problem is that you're using action words for a descriptive API. You should use something like \"Repeating\"…",{"value":140,"source":47,"evidence":141},"Regexes are rarely generated programmatically, so little need",[142],{"id":143,"by":144,"text":145},"14736602","anentropic","How often do you programmatically generate regexes though? I tend to find that regex patterns are effectively constants in the program And if it's just for readability it seems a…",[147,155,164],{"value":148,"source":47,"evidence":149},"Operator overloading for repeats and alternation",[150,154],{"id":151,"by":152,"text":153},"14731742","orf","Interesting, how does this compare to PyParsing[1]? It seems that pyparsing does a lot of this already. Not that you shouldn't write your own, mind you! Some improvements could…",{"id":136,"by":137,"text":138},{"value":156,"source":47,"evidence":157},"Rename classes to more descriptive names",[158,159,160],{"id":128,"by":129,"text":130},{"id":136,"by":137,"text":138},{"id":161,"by":162,"text":163},"14734812","masklinn","Seq is odd, to me Seq('a', 'm') says it matches 'am'. Why not overload X to support filtered forms instead? E.g X() is \".\", X(from_, to_) is $from-$to, X(items) is [$items] and…",{"value":165,"source":47,"evidence":166},"Support for parsing existing regexes",[167],{"id":128,"by":129,"text":130},[169,177],{"value":170,"source":47,"evidence":171},"How does this compare to pyparsing or parser combinators",[172,173],{"id":151,"by":152,"text":153},{"id":174,"by":175,"text":176},"14731879","carlochess","Hi, what's the diference between this project and a parser combinator?",{"value":178,"source":47,"evidence":179},"Why not use Python verbose regex mode",[180],{"id":181,"by":182,"text":183},"14734257","ddebernardy","I'm confused. Doesn't Python offer verbose regular expressions complete with comments? https:\u002F\u002Fdocs.python.org\u002F3\u002Flibrary\u002Fre.html#re.VERBOSE ``` a = re.compile(r\"\"\"\\d + # the…",[185,192,198,202,209],{"value":186,"source":47,"evidence":187},"rx.el in Emacs",[188],{"id":189,"by":190,"text":191},"14731924","avar","In case you aren't aware of this, what you've made is very similar to the rx.el[1] that's shipped with Emacs since 21.1 (released in 2001). Many of the comments here are…",{"value":193,"source":47,"evidence":194},"CL-PPCRE tree syntax",[195],{"id":196,"by":129,"text":197},"14732312","In Common Lisp, the library CL-PPCRE [0] is used for regexes, and has an \"AST\"-syntax like this. It supports full Perl-compatible regular expressions in both the tree syntax as…",{"value":199,"source":47,"evidence":200},"pyparsing",[201],{"id":151,"by":152,"text":153},{"value":203,"source":47,"evidence":204},"Python VerbalExpressions",[205],{"id":206,"by":207,"text":208},"14733246","rohitpaulk","A more mature version: https:\u002F\u002Fgithub.com\u002FVerbalExpressions\u002FPythonVerbalExpressions",{"value":210,"source":47,"evidence":211},"compose-regexp.js",[212],{"id":94,"by":95,"text":96},{"comments":214,"answered":40,"key":215},15,[216,219,222],{"id":217,"text":218},"14732632","I may add synonyms for those classes, so, it is just a matter of adding: Repeat = Times etc. you wouldnt use these structures in python code, you use them to build your regex…",{"id":220,"text":221},"14732655","Seq stands for a-z or 0-9 which can be used only in Include and Exclude. When you write Include(Seq('a', 'm')) it means you are including a character from that sequence in a…",{"id":223,"text":224},"14735445","hmm, I think it is good, maybe p0 = X('a', 'z'). I like it.",{"commenters":226,"max_depth":32,"maker_replies":214,"first_comment_mins":227,"lifespan_hours":228},34,23,26,[230,232,236,238,240,241,243,245,247,250,251,253,255,258,262,264,266,267,271,275,278,280,281,285,286,287,289,290,292,293,297,300,303,306,308,311,314,315,319,321,324,325,326,328,331,333,335,337,341,343,345,348,351,353,355],[189,39,42,231,190,39],"maker\u002Fneutral\u002Fidea",[233,39,39,234,235,39],"14732578","commenter\u002Fneutral\u002Fnone","bhrgunatha",[128,33,33,237,129,39],"project\u002Fcritical\u002Fdesign",[217,33,39,239,11,33],"maker\u002Fneutral\u002Fdesign",[220,33,39,239,11,33],[161,33,42,242,162,39],"project\u002Fneutral\u002Fdesign",[223,33,39,244,11,33],"project\u002Fpositive\u002Fdesign",[246,33,42,242,162,39],"14738134",[248,33,39,249,11,33],"14738317","maker\u002Fneutral\u002Fnone",[136,33,33,237,137,39],[252,33,42,242,162,39],"14738171",[254,33,39,242,11,33],"14739485",[196,256,39,257,129,39],2,"other\u002Fneutral\u002Fidea",[259,256,39,260,261,39],"14733010","other\u002Fneutral\u002Fperformance","kazinator",[50,42,33,263,51,39],"project\u002Fcritical\u002Fidea",[94,42,40,265,95,39],"project\u002Fpositive\u002Fidea",[105,42,40,265,106,39],[268,42,42,269,270,39],"14731937","project\u002Fneutral\u002Fidea","baq",[272,42,39,273,274,39],"14732076","other\u002Fneutral\u002Fnone","ivanbakel",[276,42,39,273,277,39],"14732941","rtpg",[279,42,39,273,270,39],"14735094",[121,42,33,237,122,39],[282,42,39,283,284,39],"14732059","other\u002Fneutral\u002Fdesign","fiddlerwoaroof",[58,42,39,231,11,33],[65,42,33,237,66,39],[69,42,39,288,11,33],"maker\u002Fneutral\u002Fperformance",[151,31,42,269,152,39],[291,31,39,249,11,33],"14731825",[54,40,33,237,55,39],[294,40,39,295,296,39],"14731991","other\u002Fneutral\u002Fdocs","klenwell",[298,40,39,295,299,39],"14732516","kqr",[301,40,39,234,302,39],"14732525","blibble",[304,40,39,234,305,39],"14732714","bpicolo",[307,40,39,244,11,33],"14732039",[309,40,42,310,55,39],"14732098","project\u002Fmixed\u002Fidea",[312,40,39,313,11,33],"14732106","maker\u002Fpositive\u002Fidea",[80,40,39,231,11,33],[316,40,39,317,318,39],"14732926","commenter\u002Fcritical\u002Fidea","baudehlo",[181,320,33,263,182,39],6,[322,320,39,317,323,39],"14734506","always_good",[117,32,33,263,118,39],[77,32,39,231,11,33],[98,327,40,265,99,39],8,[329,34,39,273,330,39],"14732433","rnhmjoj",[109,332,40,265,110,39],10,[206,334,39,273,207,39],11,[336,334,39,273,11,33],"14740391",[338,339,39,340,11,33],"14740095",12,"maker\u002Fneutral\u002Fdocs",[143,342,33,263,144,39],13,[174,344,42,269,175,39],14,[346,344,39,273,347,39],"14732064","yablak",[349,214,39,295,350,39],"14732768","bane",[352,214,39,273,323,39],"14734604",[354,214,39,273,350,39],"14735321",[356,214,39,340,11,33],"14740399",[358,361,362,366,369,372,375,378,381,384,387,390,393,396,399],{"id":359,"t":360,"points":42,"comments":39},"14728722",1499584156,{"id":4,"t":12,"points":14,"comments":15},{"id":363,"t":364,"points":365,"comments":256},"18297833",1540429894,17,{"id":367,"t":368,"points":256,"comments":39},"22402209",1582528049,{"id":370,"t":371,"points":31,"comments":256},"22429285",1582764924,{"id":373,"t":374,"points":256,"comments":39},"22830229",1586496258,{"id":376,"t":377,"points":33,"comments":39},"22832948",1586526531,{"id":379,"t":380,"points":33,"comments":33},"22852038",1586737128,{"id":382,"t":383,"points":256,"comments":39},"23088451",1588747583,{"id":385,"t":386,"points":320,"comments":39},"23752485",1594067899,{"id":388,"t":389,"points":327,"comments":39},"23807035",1594509297,{"id":391,"t":392,"points":33,"comments":39},"23936691",1595575493,{"id":394,"t":395,"points":256,"comments":39},"25019100",1604781866,{"id":397,"t":398,"points":256,"comments":39},"25813805",1610910473,{"id":400,"t":401,"points":33,"comments":39},"30737753",1647725474,[403,407,412,417,422,426],{"id":404,"name":405,"points":406,"category":20},"14737118","Seashells",356,{"id":408,"name":409,"points":410,"category":411},"14718051","Globe",258,"creative",{"id":413,"name":414,"points":415,"category":416},"14725878","darkmatter",180,"languages",{"id":418,"name":419,"points":420,"category":421},"14730354","crackcoin",171,"finance_crypto",{"id":423,"name":424,"points":425,"category":20},"14714386","Play with Kubernetes",164,{"id":427,"name":428,"points":429,"category":430},"14744331","BotEngine",124,"ai",false,"v2",{"id":434,"name":5,"line":6,"ai":431,"cat":20,"year":13,"points":14,"comments":15,"rec":28,"s":435,"top":18,"kw":436,"maker":11,"domain":10,"tier":19,"attempts":214,"strip":437,"url":9,"mix":438,"praise":91,"objection":114,"sub":21},14731631,-0.23,[24,25,21,26,27],"3010330100155301001301000300110550013000",[31,32,33,34],1794036557111]