Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>For developers trying to write regular expressions that are easy to grok and maintain, I wonder whether this sort of approach would offer anything that <code>re.VERBOSE</code> does not provide already.</p> <p>For beginners, your idea might have some appeal. However, before you go down this path, you might try to mock up what your declarative syntax would look like for more complicated regular expressions using capturing groups, anchors, look-ahead assertions, and so forth. One challenge is that you might end up with a declarative syntax that is just as difficult to remember as the regex language itself.</p> <p>You might also think about alternative ways to express things. For example, the first thought that occurred to me was to express a regex using functions with short, easy-to-remember names. For example:</p> <pre><code>from refunc import * pattern = Compile( 'a', Capture( Choices('b', 'c'), N_of( 'd', 1, Infin() ), N_of( 'e', 0, Infin() ), ), Look_ahead('foo'), ) </code></pre> <p>But when I see that in action, it looks like a pain to me. There are many aspects of regex that are quite intuitive -- for example, <code>+</code> to mean "one or more". One option would be a hybrid approach, allowing your user to mix those parts of regex that are already simple with functions for the more esoteric bits.</p> <pre><code>pattern = Compile( 'a', Capture( '[bc]', 'd+', 'e*', ), Look_ahead('foo'), ) </code></pre> <p>I would add that in my experience, regular expressions are about learning a thought process. Getting comfortable with the syntax is the easy part.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload