javascript – match string against the array of regular expressions

Using a more functional approach, you can implement the match with a one-liner using an array function: ECMAScript 6: const regexList = [/apple/, /pear/]; const text = “banana pear”; const isMatch = regexList.some(rx => rx.test(text)); ECMAScript 5: var regexList = [/apple/, /pear/]; var text = “banana pear”; var isMatch = regexList.some(function(rx) { return rx.test(text); });

XPath 1.0 to find if an element’s value is in a list of values

You can check multiple conditions inside the same square brackets: /Location/Addr[State=”TX” or State=”AL” or State=”MA”] Or if you have a really long list, you can create a list of states and use the contains() function. /Location/Addr[contains(‘TX AL MA’, State)] This will work fine for two-letter state abbreviations. If you want to make it more robust … Read more

JavaScript: difference between a statement and an expression?

Are all statements also expressions? “Wherever JavaScript expects a statement, you can also write an expression. Such a statement is called an expression statement. The reverse does not hold: you cannot write a statement where JavaScript expects an expression. For example, an if statement cannot become the argument of a function.” This is comes from … Read more

What’s the difference between anonymous methods (C# 2.0) and lambda expressions (C# 3.0)? [duplicate]

Lambda expressions can be converted to delegates or expression trees (with some restrictions); anonymous methods can only be converted to delegates Lambda expressions allow type inference on parameters: Lambda expressions allow the body to be truncated to just an expression (to return a value) or single statement (in other cases) without braces. Lambda expressions allow … Read more

What’s the difference between # , % and $ signs in Struts tags?

Use of # (pound sign) OGNL is used to refer to objects in the ActionContext as follows: objectName: object in the ValueStack (default/root object in the OGNL context), such as an Action property #objectName: object in the ActionContext but outside of the ValueStack, specifically… #objectName: ActionContext object that has been created using the Struts2 data … Read more