Problem:

Hello ... Can anyone tell me that why I obtained this error that which of the adhering to incorrectly matches the term with its location?


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

Tbelow are 2 problems here:

The regex ofPattern.matcherwill certainly not look for the full string unmuch less you add a leading^(start of regex) and also trailing$(finish of regex).file.getName()will rerotate the name including file extension.

You are watching: Which of the following incorrectly matches the term with its location?

So, there are two feasible solutions:

1) You could adjust the regex of the pattern so the matches does just complement the full file-name:

int count=0;Pattern pattern = Pattern.compile("^" + patternName + "\.?.+$");for(Data f: fileList) Matcher matcher = pattern.matcher(f.getName()); if(matcher.find()) count++; Brief explacountry of the regex:

^NUTS\.?.+$^ $ # Start and finish of the regex, to match the entire file-name NUTS # The file name you want to inspect \.?.* # An (optional) file extension (i.e. `.txt`)2) You can rerelocate the extension, and use an.equals:

int count=0;for(Documents f: fileList) String fileNameWithoutExanxiety = f.getName().split("\.")<0>; if(patternName.equals(fileNameWithoutExtension)) count++;
*
answeredMar 26Huzaifa86.2k points
ask associated questioncomment

Your comment on this answer:

Your name to screen (optional):
Email me at this address if a comment is included after mine:Email me if a comment is added after mine

Privacy: Your email deal with will certainly only be offered for sending these notifications.
Anti-spam verification:

What is the shade of the sky?
To protect against this verification in future, please log in or register.
Add commentCancel

Related questions


0 votes
1 answer44 views
44 views
Which of the complying with best explains the term "review consistency"?
Problem: This is a dilemma that I require help with: which of the complying with finest explains the term "check out consistency"?
askedApr 1rakib151.5k points
0 votes
1 answer38 views
38 views
Which consistent expression string matches any kind of sequence of personalities of any kind of length?
Problem: What should I perform if I can"t find a solution anywhere: Which consistent expression string matches any kind of sequence of characters of any kind of length?
*
askedJun 13Mezbah188k points
0 votes
1 answer1 view
1 view
excellent beasts and wbelow to discover them openload
Problem: ======= excellent beasts and wbelow to find them openload
*
asked22 hours agonila182k points
0 votes
1 answer24 views
24 views
Which continuous expression character matches zero or more of the previous character?
Problem: I"d appreciate it if you can respond to this : Which constant expression character matches zero or even more of the previous character?
*
askedJun 13Mezbah188k points
0 votes
1 answer13 views
13 views
Write a continuous expression which matches a email resolve .
Problem: Is tbelow some means to deal with this? > Write a consistent expression which matches a email attend to .
*
askedMay 10Isac Christiaan116k points
0 votes
1 answer23 views
23 views
Check if one string is substring of another
Problem: Please,I desire a response : Check if one string is substring of another
*
askedMay 30Sawyer Parviz221k points
0 votes
1 answer9 views
9 views
Check if a string is a substring of an additional string in java
Problem: Can anyone help me via this issue? >Check if a string is a substring of one more string in java.

See more: Consulado Mexicano En Kansas City, Consulado De Carrera De México En Kansas City


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