Questions tagged [matcher]

1

votes
1

answer
178

Views

Why am I getting InvalidUseOfMatchers build error here?

This code compiles and debugs well, but when I do a maven build in Eclipse the unit test and the build fails. I don't understand where is the misuse of the matchers here? Thanks. [ERROR] Errors: [ERROR] Tests.MyTest() » InvalidUseOfMatchers @RunWith(SpringRunner.class) @ContextConfiguration(clas...
Yoan
1

votes
2

answer
72

Views

How to Search and count pattern from list of files?

I have a list of files in a folder and need to search 3 patterns/words and count no. of occurrences of specific types. Example, in these 3 patterns I will a colors (Red, Blue, Green etc..) and each of these colors has START (First index) and END (last Index). I need to fetch the count each of these...
Uvais
1

votes
0

answer
137

Views

Python: Spacy rule-based matcher syntax questions

I am using the rule-based matcher in spacy to look for some patterns in a text. This is an example: pattern = [{'POS':'DET'},{'DEP':'nsubj', 'OP' : '+'}, {'LEMMA':'can'},{'ORTH': 'but'},{'ORTH': 'need'},{'ORTH': 'not'} I want to make my query more efficiënt, so what I want to do is: specify that th...
Tom
1

votes
2

answer
48

Views

Optimize Finding Words in Paragraph

I'm searching for words in a paragraph but it takes ages with long paragraphs. Hence, I want to remove the words after I find it in the paragraph to shorten the number of words I have to go through. Or if there's a better way to make this efficient do tell! List list = new ArrayList(); for (String w...
dude8998
1

votes
1

answer
68

Views

Howto make ExampleMatcher with containing just one property?

Howto implement ExampleMatcher, with containinig just one property at randomly from my class and ignore the other properties? Assume my class like this : Public Class Teacher() { String id; String name; String address; String phone; int area; ..other properties is here... } If I want to match by the...
Jigu Jigu
1

votes
1

answer
1.1k

Views

java regex matcher

codes = new Vector(); titles = new Vector(); urls = new Vector(); lecturers = new Vector(); while (m.find()) { String courseCode = m.group(1); String courseTitle = m.group(2); String courseURL = url; String lecturerName = m.group(4); codes.add(courseCode); titles.add(courseTitle); urls.add(courseURL...
Becky
1

votes
2

answer
324

Views

java pattern and matcher

I am using Pattern and Matcher classes from Java to parse a link file script. The text I need is in the SECTIONS part: SECTIONS { .text : {} > FAST_MEM /* Link all .text sections into ROM */ .intvecs : {} > 0x0 /* Link interrupt vectors at 0x0 */ .data : /* Link .data sections */ { tables.obj(.data)...
Mike
1

votes
1

answer
241

Views

Unable to verify subset of arguments passed to mocked method in specs2

Here's a simple specification reproducing the issue: package ro.igstan.learning import org.specs2.matcher.ThrownExpectations import org.specs2.mock.Mockito import org.specs2.mutable.Specification import org.specs2.specification.Scope class LearningSpecs2 extends Specification { trait Logger { def er...
Ionuț G. Stan
1

votes
1

answer
6k

Views

Java — Patterns — Matcher.group()?

So I have a document, and a specified n-gram target string. I'm trying to find the indexes of all occurrences of the target string. final Pattern WORD_PATTERN = Pattern.compile('\\w+'); Matcher matcher = WORD_PATTERN.matcher('the lazy dog, jumps, the lazy dog.'); So the string is 'the lazy dog, jum...
Ryan Yu
1

votes
1

answer
447

Views

Java regex partial match with period

In Java I am using Pattern and Matcher to find all instances of '.A (a number)' in a set of strings to retrieve the numbers. I run into problems because one of the words in the file is 'P.A.M.X.' and the number returns 0. It won't go through the rest of the file. I've tried using many different regu...
M. Dearning
1

votes
1

answer
445

Views

Regex on Java: avoiding unnecessary “greedy” strategy by Matcher class

I'm trying to develop a regex to look for a sequence of tags inside a string. For example, I can have the tag (NP .*) at least one time (can be multiple times), followed by a punctuation symbol (in this case a ./.). If there's another tag between de (NP) and the ./. (like the VP in the example below...
Felipe Leão
1

votes
1

answer
1.3k

Views

gmock matcher doesn't match my arguments by reference

I have a mocked function in a class like int foo(const bar& b) const; which is mocked like MOCK_CONST_METHOD1(foo, int(const bar& b)); for which I've set set some default actions like ON_CALL(anObject, foo(bar(0,0))).WillByDefault(Return(1)); My code under test calls anObject.foo(bar(0,0); but inste...
Kie
1

votes
1

answer
261

Views

Custom RSpec routing matcher for all four HTTP verbs?

I'm writing a RSpec test suite of our routes for a rather large Rails 3 application. Many of the routes use 'MATCH', but none of them should, especially since we'll have to rewrite them as we transition to Rails 4. Most of my it blocks look something like this: it 'with /comments/account/100' do exp...
Kyle Carlson
1

votes
4

answer
1.1k

Views

Java Matcher slow regex

This is very simple regex yet, it runs for over 30 seconds on a very short string: (i7 3970k @ 3.4ghz) Pattern compile = Pattern.compile('^(?=[a-z0-9-]{1,63})([a-z0-9]+[-]{0,1}){1,63}[a-z0-9]{1}$'); Matcher matcher = compile.matcher('test-metareg-rw40lntknahvpseba32cßáàâåäæç.nl'); boolean ma...
Phoenix the II
1

votes
1

answer
55

Views

writing a regular expression in java for a string present in between a line

My input string is: subtype=forward,level=notice,vd=root,srcip=10.100.1.121,srcport=55844,srcintf=port1,dstip=173.193.156.43,dstport=80,dstintf=port16,sessionid=1224203695,status=close subtype=forward,level=notice,vd=root,srcip=10.100.1.121,srcport=55844,srcintf=port1,dstip=173.193.156.43,dstport=80...
Neelutpol
1

votes
1

answer
68

Views

Matcher creates extra group at the end of string

I've faced with strange behavior of java.util.regex.Matcher. Lets consider example: Pattern p = Pattern.compile('\\d*'); String s = 'a1b'; Matcher m = p.matcher(s); while(m.find()) { System.out.println(m.start()+' '+m.end()); } It produces output: 0 0 1 2 2 2 3 3 I can understant all lines except la...
Gusev Dmitry
1

votes
1

answer
134

Views

Matcher. How to get index of found group?

I have sentence and I want to calculate words, semiPunctuation and endPunctuation in it. Command 'm.group()' will show String result. But how to know which group is found? I can use method with 'group null', but it is sounds not good. String input = 'Some text! Some example text.' int wordCount=0; i...
user2963950
1

votes
3

answer
1.3k

Views

How to test if a `Some[String]` contains some other string?

Say I have a value which is Some('aaabbbccc'), I want to test if the value inside the Some contain some other string. I tried: val myvalue = Some('aaabbbccc') myvalue must beSome(contain('bbb')) It can't compile, but I can't find out a working one. How to write such an assertion?
Freewind
1

votes
1

answer
1.2k

Views

Writing custom matchers that play nicely with Hamcrest AllOf / CombinableMatcher matchers

I am trying to compose two matchers, so that instead of writing assertThat(response, hasStatusCode(OK)); assertThat(response, hasMessage('Some message.')); I can write something like assertThat(response, both(hasStatusCode(OK)) .and(hasMessage('Some message.'))); However, I am getting undesirable s...
neuronotic
1

votes
2

answer
688

Views

Regular expression java to extract the balance from a string

I have a String which contains ' Dear user BAL= 1,234/ '. I want to extract 1,234 from the String using the regular expression. It can be 1,23, 1,2345, 5,213 or 500 final Pattern p=Pattern.compile('((BAL)=*(\\s{1}\\w+))'); final Matcherm m = p.matcher(text); if(m.find()) return m.group(3); else retu...
Paras Dhawan
1

votes
1

answer
83

Views

Replace multiple substrings within a string [duplicate]

This question already has an answer here: Java: replace a set of characters with other different characters 4 answers I want to replace certain substrings with a replacement, both defined within a Hashmap. An example is the following: import java.util.HashMap; import java.util.regex.Matcher; import...
Rolch2015
1

votes
2

answer
94

Views

Replacing Substring in Java

I have situation in Java where I am reading contents of file in String. It is something like this - String S = 'source NB_System timestamp 2015-6-25 22:39:41:455 TTL 0 ' I want to delete the timestamp from the string - timestamp 2015-6-25 22:39:41:455 Timestamp is creating issues in comparing re...
Faiz Ali
1

votes
1

answer
116

Views

regexp negative lookahead with groups

I try to use regexp with negative lookahead and with groups. Unfortunately it does not work as expected, so I need a helping hand. I need to parse out the sizes (inches) at the end of a string which can be the format 'Tony Hawk 39.75'' --> 39.75' or with a length x width 'Tony Hawk 39.75' x 8.75''...
megloff
1

votes
1

answer
1.9k

Views

DescriptorMatcher OpenCV train()

The Documentation of OpenCV mentions the function 'train()' within a DescriptorMatcher. 'virtual void cv::cuda::DescriptorMatcher::train ( ) pure virtual Trains a descriptor matcher. Trains a descriptor matcher (for example, the flann index). In all methods to match, the method train() is...
Jürgen K.
1

votes
1

answer
46

Views

Using Matcher to extract URL domain name

static String AdrPattern='http://www.([^&]+)\\.com\\.*'; static Pattern WebUrlPattern = Pattern.compile (AdrPattern); static Matcher WebUrlMatcher; WebUrlMatcher = WebUrlPattern.matcher ('keyword'); if(WebUrlMatcher.matches()) String extractedPath = WebUrlMatcher.group (1); Considering above codes,...
lonesome
1

votes
1

answer
85

Views

Implementing a Negative Lookahead in Regex to exclude a block of code if it contains a certain string

This is a follow up to an original question I posted here, but I would appreciate help in expanding its capabilities a bit. 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 session-sta...
user2150250
1

votes
1

answer
632

Views

Hamcrest matcher fails to match Boolean type property

For class A; public class A { Integer value; Integer rate; Boolean checked; } I am constructing a custom Matcher like this; Matchers.hasItems(allOf( hasProperty('value', equalTo(value)), hasProperty('rate', equalTo(rate)))) to check if a list of A contains the one with 'value' == value && 'rate' ==...
buræquete
1

votes
2

answer
42

Views

Find the first word using pattern group

I am having problem in finding first word in below file names. 12345.pdf , 12345 203 1525345.pdf , 12345_xxx.pdf , 12345-xxx.pdf , 12345 203-1525345.pdf , Smith 12345 03012016.pdf , Smith 12345 03012016-1.pdf I am using pattern ({ln}\\w+?)[_\\s-](\\w+?_)?({dc}\\w+?).(\\w+) and fetching value of ke...
Rohit Rawat
1

votes
2

answer
197

Views

Why isn't java.util.regex.matcher not matching all instances in this string?

I have the following code: http://ideone.com/mFUaqG import java.util.regex.Matcher; import java.util.regex.Pattern; class RegexUtils { private static final Pattern resourceURLCSS = Pattern.compile('url\\([\'\'](((?!://).)*)[\'\']\\)'); private static final Pattern resourceURLHTML = Pattern.co...
gdoug
1

votes
1

answer
1k

Views

C# / .NET equivalent for Java Matcher.find and Matcher.group

I have seen that there are some posts regarding the Java Matcher class, but I was not able to find one regarding the specific methods find() and group(). I have this piece of code, where Lane and IllegalLaneException have already been defined: private int getIdFromLane(Lane lane) throws IllegalLaneE...
Biurrun
1

votes
1

answer
116

Views

RSpec starts_with matcher variant using regular expressions

Is there a variant of the RSpec start_with matcher that will use regular expression matching instead of equality when examining arrays of strings? (I don't mind writing my own; but I don't want to re-invent the wheel.) Specifically, I want to have a spec that looks like this: it 'begins with the st...
Zack
1

votes
2

answer
324

Views

Setting up regex in Pattern object for java string

Am trying to get all matches in a java string. The matches must be bases and powers in a math equation. As you know, bases and powers could be negative and decimals as well. I have the pattern, regex and matcher set up. It looks something like this, but it is not giving me what I expect. I guided my...
i_o
1

votes
1

answer
179

Views

Java Regex - Capturing everything outside quotes

TLDR: I'm looking to capture everything outside of quotation marks, but I seem to fail to do so in Java with this regex \'|'(?:\'|[^'])*'|([^\']+) while it works on websites such as http://myregexp.com/. Can anyone point me what I'm doing wrong ? Hi, I'm currently trying to analyse a .java source co...
Beerbossa
1

votes
1

answer
41

Views

Extract Substring from Regex [duplicate]

This question already has an answer here: Java Regex Error - No group 1 1 answer I have an input string that should look like this in java: String input = add entity , Now I want to check, whether a given String has the right format or not. If so I want to get the handed words. I already have the c...
Carle B. Navy
1

votes
1

answer
382

Views

Java: extract group number from Matcher

Very short question, it is possible to extract groups numbers, found by the Matcher? for example here is my code: Pattern k = Pattern.compile('(рис.\\s(\\d+)|[Рр]исунок\\s(\\d+)|[Рр]исунку\\s(\\d+)|fig.\\s(\\d+)|[fF]igure\\s(\\d+))'); Matcher m = k.matcher(DOMNode.getTextContent(...
Vitaliy
1

votes
2

answer
4.2k

Views

Escaping dollars groovy

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 strList = new ArrayList(); Pattern pattern = Patter...
GiLA3
1

votes
1

answer
653

Views

replaceAll() vs. replaceAll(…, Matcher.quoteReplacement)

Hello :D short question: What is the difference between String geb = tf_datum.getText(); String sep = ''; //sep is short for seperator geb = geb.replaceAll('\\.', sep); geb = geb.replaceAll('\\,', sep); geb = geb.replaceAll('\\-', sep); geb = geb.replaceAll('\\ ', sep);` and String geb = tf_datum....
Jana
1

votes
1

answer
61

Views

JMock matchers with setAttribute(String, Object)

I am facing issue while expecting a setAttribute call from a mock. MyClass { public final void setAttribute(String name, Object value) { // Do Something } myClass.setAttribute('Key', 'Value'); While invoking the setAttribute operation, String is passed as a value. I have a mock of the above class by...
Rachit Singhal
1

votes
1

answer
292

Views

In TestFX version 4, how can I wait until an element of the GUI becomes visible?

What Matcher should I use? visible() seems no longer available and unfortunately I could not find an alternative in the org.hamcrest library. Thanks in advance!
Adam Papp
1

votes
2

answer
47

Views

Multiple regex patterns to find. Java

I need to calculate separately number of words and sentences in string and i have these two methods which works fine: Pattern pattern = Pattern.compile('\\w+\\s|\\w+\\,|\\w+\\.|\\w+\\?|\\w+\\!*$'); Matcher match1 = pattern.matcher(s); while(match1.find()) { counterWords++; } and for sentences: Pa...
Yurko

View additional questions