如何做复杂的条件或正则expression式在玉器

我有一个有趣的挑战,不知道如何去解决它。 我从我的mailchimp中提取订阅者列表,并在数据中填充我网站上的成员页面。 我注册的一个领域是“网站或LinkedIn个人资料url”。

我想要做的是,检查他们是否提供了一个linkedin地址,如果是的话,把他们的url放在linkedin member插件中,如果没有使用其他数据来创build一个简单的个人资料,名称网站,标题等。

我的问题是我不能说,如果data.websiteField.match(/ linkedin /)内玉,所以我要么传递数据到一些客户端JavaScript,我有麻烦或做别的事情。

以下是从mailchimp返回的数据示例

[ // this first bit is just the fields [ "email address", "first name", "last name", "role", "organization", "headline", "website", "areas of interest", "please email me about:", "member_rating", "optin_time", "optin_ip", "confirm_time", "confirm_ip", "latitude", "longitude", "gmtoff", "dstoff", "timezone", "cc", "region", "last_changed" ], [ // and here's the first user "woop@booomshakala.com", // haha, just hiding some data "Woop", "Shak", "Tester", "ShakaCo", "Whooooooper", "http://linkedin.com/in/costamichailidis", // hit me up sometime "Creativity, Innovation, Ideas and Science", "Job Placement, Internships, Recruitment & Retention, Technology & MOOCs, Measurement & Evaluation, Documentation & Dissemination", 2, "2013-03-28 19:28:55", "173.52.122.111", "2013-03-28 19:29:12", "173.52.122.111", "40.7648000", "-73.7775000", "-5", "-4", "America/New_York", "US", "NY", "2013-03-28 19:29:12" ] ] 

任何帮助将摇滚!

另外,我正在使用快递。 快递是否使客户端JavaScript的本地化?

客户端正则expression式

Jade允许你在行首使用-修饰符执行任意的javascript

 - if (profile.websiteField.match(/linkedin/) // render linkedin profile here - else // render simple profile here 

服务器端正则expression式

我认为格式化configuration文件信息服务器端并将renderLinkedIn布尔型字段设置为true或false会更简单

 function displaySignUpPage(req, res) { var profile = formatMailChimpData() // profile now looks like // { // "email address": "woop@booomshakala.com", // "first name": "Noah", // ... // } var linkedInRegex = /linkedin/; profile.renderLinkedIn = linkedInRegex.test(profile.website) // set renderLinkedIn to true or false // say your jade view is called signUpPage.jade var pageData = { title: 'Register', profile: profile } res.render('signUpPage', pageData) } function formatMailChimpData() { var mailChimpData = [ [ "email address", "first name", "last name", "role", "organization", "headline", "website" // other fields truncated ], [ "woop@booomshakala.com", // haha, just hiding some data "Noah", "Isaacson", "Tester", "ShakaCo", "Whooooooper", "http://www.linkedin.com/pub/noah-isaacson/59/6a2/553" ] ] // mailChimp puts the keys as the first entry var mailChimpFields = mailChimpData[0] var mailChimpProfile = mailChimpData[1] // make profile into key-value pairs var keyValuePairs = mailChimpFields.map(function (field, index) { var profileValue = mailChimpProfile[index] var keyValuePair = [field, profileValue] return keyValuePair }) var profile = keyValuePairs.reduce(function(prev, pair) { var key = pair[0] var value = pair[1] prev[key] = value return prev }, {}) return profile }