I'm playing around with PEG.js
How can I allow to enter exactly 2 letters?
This is my approach:
start = word
word = [A-Za-z]{2}
I used the {2}
from regex, but unfortunately it doesn't work with PEG.js.
I'm playing around with PEG.js
How can I allow to enter exactly 2 letters?
This is my approach:
start = word
word = [A-Za-z]{2}
I used the {2}
from regex, but unfortunately it doesn't work with PEG.js.
You can specify a letter class, then use two letters for your word. Although the syntax isn't pretty, I couldn't find another way in the documentation.
start = word
word = letter letter
letter = [A-Za-z]
As far as I see it you can use two options. The first option accepts only a word with two letters.
start = word
word = [A-Za-z][A-Za-z]
This second option does some post-processing in javascript.
start = word
word = word:([A-Za-z]+)
{
if(word.length != 2) error("Word does not have two letters);
else return word;
}