H
H
HAbRAhabp2016-07-01 21:13:32
Regular Expressions
HAbRAhabp, 2016-07-01 21:13:32

Route for Cyrillic in Express?

I'm trying to make the router skip expressions, with letters and symbols, like a-zA-Z0-9А-Яа-я_. How do I do it:

rootApp.all(/\+(\w+|\p{L}+)/, function (req, res, next) {
    res.cookie("referer", req.params[0]);
    res.send(req.params);
});

But in the end...
GET /+А - 404 NOT FOUND
GET /+ref - {"0":"ref"}
GET /+ref_123ру_ - {"0":"ref_123"}

How to make the parser skip the Cyrillic alphabet?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
H
HAbRAhabp, 2016-07-02
@HAbRAhabp

Finally did this:

rootApp.all(/\+(\S+)/, function (req, res, next) {
        var decodedPath = decodeURIComponent(req.path),
            regexp = /\+[a-zA-Z0-9А-Яа-я_]+/;
    
        var executed = regexp.exec(decodedPath);
        if (executed != null) {
            var parsed = executed[0].slice(1);
    
            res.cookie("referer", parsed);
            res.send(parsed);
        }
        else next();
    });

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question