regex - Java Regular Expression doesn't find a match -


I'm having Java regex problems. The string that matches this string is as follows: 378-Columbian Forecasting Yr-NB-Q-Columbian_NB I need to remove which is between first and second - .

Pattern Model REGEx = Pattern.compile ("[^ -] {15,} [^ -]"); Matcher M = Model REGEx.matcher (temp); String model = m.group (0); My argument behind this regex [^ -] {15,} [^ -] :

is that what I want to do is between the hyphen so i [^ -] was used. There are several examples of text between hyphen, so I picked up a number in a large number, which will not be picked up on small matches. So I have {15,}

my error:

  Exception in thread "main" java.lang.IllegalStateException: no mail found .util.regex.Matcher.group (Matcher.java:496) alfaSpecificEditCheck.tabTest.main at (tabTest.java:21)  

When I tested my regex pattern against string : Pattern Match When I tested this method more specifically for Java (by using this tester) the results did not match.

You need to create a regex engine find its match first. Normally we should re-run all the matching parts that we use

  pattern model REGEx = Pattern.compile ("[^ -] {15,} [^ -]" ); Matcher M = Model REGEx.matcher (temp); While (m.find ()) {// & lt; - Add this string model = m.group (0); // If you want to find at least 15 things and once again you want to find it at least 16 times, then it looks like  that your regex can be rewritten  
  Pattern model RegEx = Pattern.compile ("[^ -] {16,}"); // ^^  

Comments