matcher

Matching on Substrings in Delimited List Using Regex

冷暖自知 提交于 2019-12-12 19:16:58
问题 I'm attempting to formulate a regex in Java to capture multiple strings in a space-delimited list. Here is the string I am trying to capture from ... String output = "regulations { qux def } standards none rules { abc-123 456-defghi wxyz_678 } security { enabled }"; And I want use a regex to match on each word in the space-delimited list between the brackets immediately following rules . In other words, I would like the regex to match on abc-123 , 456-defghi , and wxyz_678 . These substrings

Use variables in pattern matcher

ⅰ亾dé卋堺 提交于 2019-12-12 09:36:22
问题 I have the following: if (mobile.matches("[0-9]{6,20}")) { ... } But would like to replace the {6,20} with variable values due to them been dynamic in some cases. I.e. int minValue = 11; int maxValue = 20 if (mobile.matches("[0-9]{minValue,maxValue}")) { ... } How can I include variables in the Reg Exp? Thanks 回答1: Use Java's simple string concatenation, using the plus sign. if (mobile.matches("[0-9]{" + minValue + "," + maxValue + "}")) { Indeed, as Michael suggested compiling it is better

During suite tests EasyMock says 0 matchers expected 1 recorded

旧街凉风 提交于 2019-12-12 08:19:39
问题 So I've been using EasyMock's class extension for a while now. All of a sudden I'm getting this exception, but only when I run the entire test suite: java.lang.IllegalStateException: 0 matchers expected, 1 recorded. at org.easymock.internal.ExpectedInvocation.createMissingMatchers(ExpectedInvocation.java:42) at org.easymock.internal.ExpectedInvocation.<init>(ExpectedInvocation.java:34) at org.easymock.internal.ExpectedInvocation.<init>(ExpectedInvocation.java:26) at org.easymock.internal

ScalaTest - writing custom matchers

橙三吉。 提交于 2019-12-12 07:59:47
问题 I am running into a problem while writing a custom matcher for NodeSeq: private def matchXML(expected: NodeSeq) = new Matcher[NodeSeq] { def apply(left: NodeSeq): MatchResult = MatchResult(left xml_== expected, "XML structure was not the same (watch spaces in tag texts)", "XML messages were equal") } This compiles, but the following piece of code: val expected : NodeSeq = ... val xml : NodeSeq = ... xml should matchXML(expected) causes: error: overloaded method value should with alternatives:

Capturing Headers in a List Using Regex

不羁的心 提交于 2019-12-12 04:16:13
问题 I have the following string I am trying to capture from (let's call it output ): ltm pool TEST_POOL { Some strings above headers records { baz:1 { ANY STRING HERE } foobar:23 { ALSO ANY STRING HERE } } members { qux:45 { ALSO ANY STRINGS HERE } bash:2 { AND ANY STRING HERE } topaz:789 { AND ANY STRING HERE } } Some strings below headers } Consider each line of output to be separated by a typical line break. For the sake of this question, let's refer to records and members as "titles" and baz

Case Insensitive filtering with lambdaj

﹥>﹥吖頭↗ 提交于 2019-12-12 03:03:25
问题 I'm attempting to familiarize myself with lambdaj, and am unsure how the best way to solve this problem. Given the following test: @Test public void test() { final List<String> l1 = new ArrayList<>(); final List<String> l2 = new ArrayList<>(); l1.add("same"); l1.add("Upper"); l1.add("lower"); l2.add("same"); l2.add("upper"); l2.add("lower"); l2.add("extra"); final List<String> l3 = Lambda.filter(Matchers.not(Matchers.isIn(l1)), l2); Assert.assertThat("There should be one item in l3", l3.size(

Replacing character with File.separator using java.regex Pattern Matcher

左心房为你撑大大i 提交于 2019-12-12 02:40:07
问题 I have a field called 'path' in back end database, which stores the path to certain resource. Instead of storing lots of backslashed (escaped) path for windows path, my idea is to let user enter the path with certain character as file separator (independent of OS). For example: original path: \\\\server\\share\\ with escaped path in db: \\\\\\\\server\\\\share\\\\ instead I want: %%server%share% and later I wanted to replace those with java's File.separator for the real thing. For this job,

Match background color of listview row Espresso

柔情痞子 提交于 2019-12-12 02:25:49
问题 I have a ListView with rows of different colors created through a custom adapter like: @Override public View getView(int position, View convertView, ViewGroup parent) { ViewHolder holder; convertView = mInflater.inflate(R.layout.row_unit, parent, false); // ... if( /* some condition */ ) { convertView.setBackgroundColor(Color.LTGRAY); } else { convertView.setBackgroundColor(Color.WHITE); } return convertView; } In a test, I would like to check whether a certain element in the list has Color

Java Regex inconsistent groups

不羁的心 提交于 2019-12-11 23:37:19
问题 Please Refer to following question on SO: Java: Regex not matching My Regex groups are not consistent. My code looks like: public class RegexTest { public static void main(String[] args) { // final String VALUES_REGEX = "^\\{([0-9a-zA-Z\\-\\_\\.]+)(?:,\\s*([0-9a-zA-Z\\-\\_\\.]*))*\\}$"; final String VALUES_REGEX = "\\{([\\w.-]+)(?:, *([\\w.-]+))*\\}"; final Pattern REGEX_PATTERN = Pattern.compile(VALUES_REGEX); final String values = "{df1_apx.fhh.irtrs.d.rrr, ffd1-afp.farr.d.rrr.asgd, ffd2

Escaping dollars groovy

↘锁芯ラ 提交于 2019-12-11 13:44:54
问题 I'm having trouble escaping double dollars from a string to be used with regex functions pattern/matcher. This is part of the String: WHERE oid_2 = $$test$$ || oid_2 = $$test2$$ and this is the closest code I've tried to get near the solution: List<String> strList = new ArrayList<String>(); Pattern pattern = Pattern.compile("\$\$.*?\$\$"); log.debug("PATTERN: "+pattern) Matcher matcher = pattern.matcher(queryText); while (matcher.find()) { strList.add(matcher.group()); } log.debug(strList)