Problem:

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?


*
askedMar 25Ifra43.4k pointseditedMar 26by Ifra
Solution:

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++;
*
answeredMar 26Huzaifa86.2k points
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.
Anti-spam verification:

What is the shade of the sky?
To avoid this verification in future, you re welcome log in or register.
Add commentCancel

Related questions


0 votes
1 answer44 views
44 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
0 votes
1 answer38 views
38 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?
*
askedJun 13Mezbah188k points
0 votes
1 answer1 view
1 view
fantastic beasts and where to uncover them openload
Problem: ======= fantastic beasts and where to discover them openload
*
asked21 hrs agonila182k points
0 votes
1 answer24 views
24 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?
*
askedJun 13Mezbah188k points
0 votes
1 answer13 views
13 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 .
*
askedMay 10Isac Christiaan116k points
0 votes
1 answer23 views
23 views
Check if one wire is substring of another
Problem: Please,I want response : examine if one string is substring the another
*
askedMay 30Sawyer Parviz220k points
0 votes
1 answer9 views
9 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


*
askedMay 9Florina Gulnar153k points
0 votes
1 answer7 views
7 views
Find a indigenous in a wire java
Problem: discover a native in a cable java.
*
askedMar 21charles mathews5.5k points
0 votes
1 answer8 views
8 views
C++ string variety of characters
Problem: C++ string variety of characters
*
askedAug 15nila182k points
0 votes
1 answer6 views
6 views
Count number of characters in a cable c++
Problem: Count variety of characters in a string c++
*
askedJul 15Sawyer Parviz220k points
Dark theme