matcher

Java regex throwing exception for no match found when pattern found in line

我只是一个虾纸丫 提交于 2019-12-19 00:37:13
问题 I am dying trying to figure out why a regex won't match. Any help is much appreciated. I'm going line by line of a web page (that works fine), but I need to pull out the links for each line. The application will check to see if there is a link in the line, but I need to actually pull out the URL. help? Pattern p = Pattern.compile("^.*href=\"([^\"]*)"); Matcher m = p.matcher(result); String urlStr = m.group(); links.add(urlStr); The error message I keep getting is this: Exception in thread

Java RegEx Matcher.groupCount returns 0

家住魔仙堡 提交于 2019-12-17 16:35:48
问题 I know this has been asked but I am unable to fix it For a book object with body (spanish): "quiero mas dinero" (actually quite a bit longer) My Matcher keeps returning 0 for: String s="mas"; // this is for testing, comes from a List<String> int hit=0; Pattern p=Pattern.compile(s,Pattern.CASE_INSENSITIVE); Matcher m = p.matcher(mybooks.get(i).getBody()); m.find(); System.out.println(s+" "+m.groupCount()+" " +mybooks.get(i).getBody()); hit+=m.groupCount(); I keep getting "mas 0 quiero mas

How to write a matcher that is not equal to something

冷暖自知 提交于 2019-12-17 16:26:41
问题 I am trying to create a mock for a call. Say I have this method I am trying to stub out: class ClassA { public String getString(String a) { return a + "hey"; } } What I am trying to mock out is: 1st instance is when(classA.getString(eq("a")).thenReturn(...);` in the same test case when(classA.getString([anything that is not a])).thenReturn(somethingelse); The 2nd case is my question: How do I match anyString() other than "a"? 回答1: With Mockito framework, you can use AdditionalMatchers ClassA

java regex match count

风格不统一 提交于 2019-12-17 00:14:19
问题 Let's say I have a file, and the file contains this: HelloxxxHelloxxxHello I compile a pattern to look for 'Hello' Pattern pattern = Pattern.compile("Hello"); Then I use an inputstream to read in the file and convert it into a String so that it can be regexed. Once the matcher finds a match in the file, it indicates this, but it doesn't tell me how many matches it found; simply that it found a match within the String. So, as the string is relatively short, and the buffer I'm using is 200

java regular expression question [closed]

六眼飞鱼酱① 提交于 2019-12-14 03:37:09
问题 This question is unlikely to help any future visitors; it is only relevant to a small geographic area, a specific moment in time, or an extraordinarily narrow situation that is not generally applicable to the worldwide audience of the internet. For help making this question more broadly applicable, visit the help center. Closed 7 years ago . I want a regular expression that can match <FONT FACE=\"Verdana\" SIZE=\"12\"> My Name is xyz </FONT> or <LI><FONT FACE=\"Verdana\" SIZE=\"12\"> My Name

how to compare two string regardless of lowercase and uppercase using angular js [duplicate]

牧云@^-^@ 提交于 2019-12-13 09:47:43
问题 This question already has answers here : How to do case insensitive string comparison? (20 answers) Closed 2 years ago . Hi I need to compare two strings regardless of the case of the letters (uppercase/lowercase). <tr ng-repeat="x in vm.partners"> <td ng-if = "'vm.partner.name' === 'vm.partners.name'" colspan="2">{{ x.name }}</td> <td ng-if = "'vm.partner.name' === 'vm.partners.name'" colspan="2">{{ x.contact.city.name }}</td> </tr> I want to check(vm.partner.name) and (vm.partners.name)

Java replace Matcher

落花浮王杯 提交于 2019-12-13 05:55:16
问题 I want to find replace part of what is matched. Example: this is awesome look at this two letter words get replaced the return would be this <h1>is</h1> awesome look <h1>at</h1> this two letter words get replaced Notice how the is and at which would match regex \b\w\w\b would be matched are replaced. This is the code I was working on. It's not finished but I am just a little confused and wondering if there is an easier way. I was searching the string and finding the matches. Then I was adding

Finding Multiple Integers Inside A String Using Regex

巧了我就是萌 提交于 2019-12-13 04:45:19
问题 I currently have this code below: Pattern intsOnly = Pattern.compile("\\d+"); Matcher matcher = intsOnly.matcher(o1.getIngredients()); matcher.find(); String inputInt = matcher.group(); What currently happens is that using Regex, it finds the first integer inside a string and separates it so that I can carry out actions on it. The string that I am using to find integers inside of has many integers and I want them all separate. How can I tweak this code so that it also records the other

Cucumber and custom RSpec matchers

☆樱花仙子☆ 提交于 2019-12-13 01:34:26
问题 I'm trying to write a custom RSpec matcher for cucumber. I require cucumber/rails/rspec in env.rb, but I still get "uninitialized constant Spec::Matchers" error. I'm using latest versions of Rspec, Cucumber and CucumberRails. What am I missing? P.S. Same matcher works fine with pure RSpec... 回答1: Are you using RSpec 2? The correct constant is now RSpec::Matchers for that. Defined in rspec/matchers . If you're not, then perhaps you haven't required spec/matchers which defines the Spec:

mockito throwing InvalidUseOfMatchersException

蓝咒 提交于 2019-12-13 01:17:33
问题 My getUserDetails class take User(custome class) and string as arguments and return User. If I use Mockito matcher as below: when(authService.getUserDetails(any(User.class),anyString())).thenReturn(any(User.class)); It gives me InvalidUseOfMatchersException 2 matchers expected, 3 found. Can't I use the above expression? 回答1: Matchers are not used for returning. .thenReturn(any(User.class)); You have to return something tangible here. Matchers are just for matching up input so that you can