Live data from Hacker News

RegExpBuilder – Create regular expressions using chained methods

github.com

11–20 of 56 posts

Re: RegExpBuilder – Create regular expressions using chained methods

#12

Looks like Linq (from .Net/C#). Pretty sexy way to write Regular Expressions if you ask me. I've "learned" regular expressions multiple times but it just never sticks, I have no idea why. It certainly doesn't help that there are several different incompatible syntaxes (so what I remember and think "should" work doesn't). I'd prefer to write RegX's in this style, however I would pay attention to performance (not that…

Regular expressions are high performance if you use automata style(Regular Language) regular expressions, which limits the use of some of the features you can use.

Modern regular expression engines in a lot of languages, actually go beyond the expressiveness of a regular language. This is what damages performance.

There is no reason why this would reduce performance... if its not doing anything crazy.

If anything your taking work away from it. Your building the tree directly here, where as parser would normally build a tree from the string. But since this is integrating into the languages RE library i'm guessing its writing that tree as a string, which is then passed into the regular expression engine, to be turned into a tree again :)

Re: RegExpBuilder – Create regular expressions using chained methods

#13

Generally, I find that if one's regexes are so complex that one needs visualizers or other aids in writing them, one doesn't have a regex problem, but a parsing problem. The method of parsing by recursive descent can often lead to much more understandable (if more verbose) "pattern matching".

Recursive descend is imperative, while regex is declarative.

Regex may be ugly, but you lose something important when you move from declarative to imperative.

Re: RegExpBuilder – Create regular expressions using chained methods

#14
post #2

Thanks, this is a lot better than writing this (even if the formatting worked here): ``` (?xi) \b ( # Capture 1: entire matched URL (?: [a-z][\w-]+: # URL protocol and colon (?: /{1,3} # 1-3 slashes | # or [a-z0-9%] # Single letter or digit or '%' # (Trying not to match e.g. "URI::Escape") ) | # or www\d{0,3}[.] # "www.", "www1.", "www2." … "www999." | # or [a-z0-9.\-]+[.][a-z]{2,4}/ # looks like domain name followed…

actually most of the comments seem to imply that whoever wrote that don't fully understand regexp syntax -- or, worst, she expects that whoever read will not

    /{1,3}                        # 1-3 slashes
    |                             #   or
    [a-z0-9%]                     # Single letter or digit or "%";

Re: RegExpBuilder – Create regular expressions using chained methods

#15

Looks like Linq (from .Net/C#). Pretty sexy way to write Regular Expressions if you ask me. I've "learned" regular expressions multiple times but it just never sticks, I have no idea why. It certainly doesn't help that there are several different incompatible syntaxes (so what I remember and think "should" work doesn't). I'd prefer to write RegX's in this style, however I would pay attention to performance (not that…

Performance is unaffected. This provides a fluent and verbose way of building a regular expression. Users of the library then feed the built regular expression into their standard regular expression engine.

Re: RegExpBuilder – Create regular expressions using chained methods

#16
post #12

Looks like Linq (from .Net/C#). Pretty sexy way to write Regular Expressions if you ask me. I've "learned" regular expressions multiple times but it just never sticks, I have no idea why. It certainly doesn't help that there are several different incompatible syntaxes (so what I remember and think "should" work doesn't). I'd prefer to write RegX's in this style, however I would pay attention to performance (not that…

Regular expressions are high performance if you use automata style(Regular Language) regular expressions, which limits the use of some of the features you can use. Modern regular expression engines in a lot of languages, actually go beyond the expressiveness of a regular language. This is what damages performance. There is no reason why this would reduce performance... if its not doing anything crazy. If anything you…

I guess it depends on your definition of "high performance."

If a regular expression runs too often, even pre-compiled (as they should be), you'll want to replace them with code written in the native language. I've gone in and replaced a one line search/replace written in RegX (compiled), with just a C-style for() loop over the wchar array, and had the memory usage drop by near 80% and performance increase by over 60%.

So high performance is all relative. However RegX isn't something I'd describe that way, even compiled. It is a nice way to write complex string parsing code quickly however.

Re: RegExpBuilder – Create regular expressions using chained methods

#17

Looks like Linq (from .Net/C#). Pretty sexy way to write Regular Expressions if you ask me. I've "learned" regular expressions multiple times but it just never sticks, I have no idea why. It certainly doesn't help that there are several different incompatible syntaxes (so what I remember and think "should" work doesn't). I'd prefer to write RegX's in this style, however I would pay attention to performance (not that…

If you're interested in something similar for .NET / C#, check out my Regextra library, specifically the Passphrase Regex Builder: https://github.com/amageed/Regextra

As the name suggests though, the focus was on passphrase criteria and it wasn't to produce a DSL for general regex building. The library also supports named templates and a few utility methods.

Re: RegExpBuilder – Create regular expressions using chained methods

#19
post #12

Earlier quoted context omitted.

Regular expressions are high performance if you use automata style(Regular Language) regular expressions, which limits the use of some of the features you can use. Modern regular expression engines in a lot of languages, actually go beyond the expressiveness of a regular language. This is what damages performance. There is no reason why this would reduce performance... if its not doing anything crazy. If anything you…

I guess it depends on your definition of "high performance." If a regular expression runs too often, even pre-compiled (as they should be), you'll want to replace them with code written in the native language. I've gone in and replaced a one line search/replace written in RegX (compiled), with just a C-style for() loop over the wchar array, and had the memory usage drop by near 80% and performance increase by over 60…

A regular expression implemented as a DFA would literally be looping over the string, and a state transition table. I don't see how performance could be bad.

It is highly dependent on the regular expression engine you use, most don't use automata because of extra features.

Re: RegExpBuilder – Create regular expressions using chained methods

#20
post #12

Earlier quoted context omitted.

Regular expressions are high performance if you use automata style(Regular Language) regular expressions, which limits the use of some of the features you can use. Modern regular expression engines in a lot of languages, actually go beyond the expressiveness of a regular language. This is what damages performance. There is no reason why this would reduce performance... if its not doing anything crazy. If anything you…

I guess it depends on your definition of "high performance." If a regular expression runs too often, even pre-compiled (as they should be), you'll want to replace them with code written in the native language. I've gone in and replaced a one line search/replace written in RegX (compiled), with just a C-style for() loop over the wchar array, and had the memory usage drop by near 80% and performance increase by over 60…

If your regex is replaceable by a simple "find_substring" or equivalent, it's slow.

If your regex is complicated, it will probably beat any naive attempt to write it into conventional string processing, short of reimplementing regexs in the first place. Especially since in many languages, "conventional string processing" may involve the creation of lots of copies and sub-copies.

Post reply on HN