Regular Expressions 101

Community Patterns

Request mask idea

3

Regular Expression
ECMAScript (JavaScript)

/
(([a-zA-Z]+)\,)|(\,[a-zA-Z]+)|([a-zA-Z]+)\(([a-zA-Z,]+)\)
/
g

Description

Do you like apis and nodejs as I do?, then this must be for you, have you noticed that all the famous apis have a common functionality? the ability to request partial responses with masks, so if you have a friend list you may want to return only a few fields you know just in case. You will end up requesting someting like /me/friends?fields=name,email,address. But also may want to return complex references like your friend's friends, so this regex let you match things like name,email,address,friends(name,email) as the 4 fields they are, then you can use a portion of the regex to extract the inner fields. Why the fancy introduction? we need some context :P enjoy

Submitted by Marco Villarreal<erick.slayer.m.v@gmail.com> - 9 years ago