Skip to content

Best way to parse ascii letters and numbers #224

Answered by j-mie6
DamianReeves asked this question in Q&A
Discussion options

You must be logged in to vote

It's not clear what exactly it means by "not be percent encoded"; whether that's supposed to be "no percent-encoded characters in the name" or what. But basically, it seems like a direct translation is probably best:

val start = oneOf('a' to 'z') | oneOf('A' to 'Z') | oneOf('.', '+', '-')
val letters = oneOf('0' to '9') | start

(you could use digit/letter, but that would be more than just ASCII in this case; depends on how strict you want to be. Or you could build a set of all the letters and use a single oneOf, which would be more efficient in this case). Then you want to stitch them together, which can probably be done with span for simplicity:

val typePurl = (start ~> many(letters)).sp…

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@DamianReeves
Comment options

Answer selected by DamianReeves
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants