Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I don't think regular expressions are going to help you much here. They might be able to do some of the really simple matching, but what you're really looking at here is a grammar parsing problem. You might want to read up on languages designed to express abstract grammars, like <a href="http://en.wikipedia.org/wiki/Extended_Backus%E2%80%93Naur_Form" rel="nofollow">Extended Backus-Naur Form</a> (EBNF). It sounds intimidating, but it's really not that hard to grasp. Once you're able to describe your grammar in a formal language, suddenly parsing it becomes much easier (at the very least, you have a specification of what kind of inputs are valid). For example, you might have the following EBNF for your problem:</p> <pre><code>expression = "every" time-unit|time-unit-list|composite-time-unit time-unit = { ordinal } "day" | "weekday" ordinal = "first" | "second" | "third" | ... </code></pre> <p>And so on. This is not a trivial job; parsing an English sentence, even a fairly restrictive one like this can be quite involved. However, it is a well-established and rigorous method.</p> <p>Once you've got your grammar defined, you can build a parser for it. This is a matter of looking for <em>terminals</em> (like "every") and then matching them to a rule. For example, you might have something like the following (pseudocode):</p> <pre><code>words = split(/\s*/,lowercase(input)) if( words[0] == "every" ) { switch( words[1] ) { case "first": case "second": case "third": ... parseTimeUnit(words); break; case "day": everyDay = true; break; ... } } </code></pre> <p>Depending on the complexity of your grammar, you might look into automatically generating the parser with something like <a href="http://en.wikipedia.org/wiki/Yacc" rel="nofollow">Yacc</a>.</p> <p>You've bitten yourself off a hunk of a problem, but it's a rewarding one to work through, so good luck!</p> <p><strong>Update</strong>: I only suggested Yacc because it's among the oldest parser generators I know of. However, there are a million of them, and a lot of them will emit Javascript for you. You can check out <a href="http://en.wikipedia.org/wiki/Comparison_of_parser_generators" rel="nofollow">Wikipedia's comparison of parser generators</a> for more information.</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. 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