Hello ... Have the right to anyone call me the why I obtained this error that which of the complying with incorrectly matches the term through its location?
There room two problems here:The regex ofPattern.matcherwill no look for the complete string unless you add a leading^(start of regex) and trailing$(end that regex).file.getName()will return the name including file extension.
You are watching: Which of the following incorrectly matches the term with its location?
So, there space two feasible solutions:
1) you could adjust the regex that the pattern so the matches does only complement the full file-name:
int count=0;Pattern pattern = Pattern.compile("^" + patternName + "\\.?.+$");for(File f: fileList) Matcher matcher = pattern.matcher(f.getName()); if(matcher.find()) count++; Short explanation that the regex:
^NUTS\\.?.+$^ $ # Start and end that the regex, to enhance the entire file-name NUTS # The document name you desire to examine \\.?.* # one (optional) record extension (i.e. `.txt`)2) You could remove the extension, and also use an.equals:int count=0;for(File f: fileList) wire fileNameWithoutExtension = f.getName().split("\\.")<0>; if(patternName.equals(fileNameWithoutExtension)) count++;
ask related questioncomment
Your comment on this answer:
|Your name to display screen (optional):|
|Email me in ~ this resolve if a comment is included after mine:Email me if a comment is included after mine|
Privacy: her email deal with will only be provided for sending these notifications.
What is the shade of the sky?
To avoid this verification in future, you re welcome log in or register.
1 answer44 views
Which that the following finest describes the hatchet "read consistency"?
Problem: This is a dilemma that i need help with: which of the following best describes the term "read consistency"?
askedApr 1rakib151.5k points
1 answer38 views
Which constant expression wire matches any type of sequence of personalities of any type of length?
Problem: What must I carry out if i can"t discover a solution anywhere: Which continuous expression cable matches any kind of sequence of personalities of any kind of length?
1 answer1 view
fantastic beasts and where to uncover them openload
Problem: ======= fantastic beasts and where to discover them openload
1 answer24 views
Which regular expression character matches zero or more of the ahead character?
Problem: I"d appreciate it if you might respond come this : Which constant expression personality matches zero or more of the previous character?
1 answer13 views
Write a consistent expression i beg your pardon matches a email attend to .
Problem: Is there some method to settle this? > create a constant expression i m sorry matches a email resolve .
1 answer23 views
Check if one wire is substring of another
Problem: Please,I want response : examine if one string is substring the another
1 answer9 views
Check if a wire is a substring of one more string in java
Problem: have the right to anyone aid me with this issue? >Check if a cable is a substring of another string in java.
See more: Some Old Norse Word For Brother, Sister, Mom And Dad, Old Norse Word For Sibling
1 answer7 views
Find a indigenous in a wire java
Problem: discover a native in a cable java.
1 answer8 views
C++ string variety of characters
Problem: C++ string variety of characters
1 answer6 views
Count number of characters in a cable c++
Problem: Count variety of characters in a string c++