how to match the key word from a text file
p>Hi all,
I have the code to match the key word and from the text. I have input like this reader.txt
Guindy National Park is located in Chennai , South India , one of the last remnants of tropical dry evergreen forest of the Coromandel Coast , Guindy Park was originally a game reserve.
and 2.txt is
located
biosphere
reserve
I am getting an output like this now.
Number of times Tim is: located
Number of times Tim is: serve
the expected output is
Number of times Tim is: located
code is as follows
**import java.io.*;
import java.io.BufferedReader;
import java.io.FileReader;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
class Classnew
{
public static String getnew()
{
String data2 = "";
try {
BufferedReader br = new BufferedReader(new FileReader("2.txt"));
String devstr;
while ((devstr = br.readLine()) != null) {
System.out.println(devstr);
data2+=devstr+"\n";
}
} catch (IOException e) {
}
return data2;
}
}
public class Findwordphrase {
public static void main(String[] args) {
Classnew classnew = new Classnew();
String data2 =classnew.getnew();
System.out.println("Data of Class2(keyWrd): " + data2);
try {
BufferedReader br = new BufferedReader(new FileReader("reader.txt"));
String devstr;
while ((devstr = br.readLine()) != null) {
String text = devstr;
String text1 = text.replaceAll(" ","").replaceAll(" "," ");
System.out.println(text1);
String[] words = text1.split(" ");
for (String word : words)
{
String regex1 = "\\b"+data2+"\\b";
Pattern pattern1 = Pattern.compile(regex1);
Matcher matcher1 = pattern1.matcher(word);
String val = null;
while (matcher1.find()) {
val = matcher1.group();
System.out.println("Number of times Tim is: " +val );
}
}
}
} catch (IOException e) {
}//try catch ends
}
}**
If i give the input like this
String regex1 = "\blocated|reserve|biosphere\b";
instead of this i am getting the result. I don't want to hard code the string. instead i want to get the value from the called file and get the result.
String regex1 = "\b"+data2+"\b";
i am missing some part to get the correct output and not able to find that. If any one could find my mistake help me. please...
View Answers
Related Tutorials/Questions & Answers:
how to match the key word from a text filehow to
match the
key word from a
text file p>Hi all,
I have the code to
match the
key word and
from the
text. I have input like this reader.txt... want to get the value
from the called
file and get the result.
String regex1
Advertisements
Java search word from text fileJava search
word from text file
In this tutorial, you will learn
how to search a
word from text file and
display data related to that
word. Here, we have created a
text file student.txt
which consists of id, name and marks of few
Search word from text file using JavaHow to Search
word from text file using Java
In this section, we are going to search a
word from the
text file. For this, we have created a swing button...
from the
text file.
Here is the code:
import java.io.*;
import
Text field save as word fileText field save as
word file Dear experts At run
how to save set of
text field contains
text into single
Word file. To save in our desktop computer. Solve my problem
click a word and search it from a fileclick a
word and search it
from a file i want to link a
word with a
file and search it form the
file by clicking it. what could the code for this process
Convert Text To Word;
In this
example, You will learn
how to convert
text to
word file. Here, we are
going to discuss about the conversion of
text to
word file.
Core... for
converting
text to
word file. This program converts the
text to
word file by using
Count repetitions of every word from an input fileCount repetitions of every
word from an input file Hello..i got to know
how can i count the repetitions of every
word present in a specific input
file?For suppose if i have a url log
file which have time,url's,ip address etc
How to make a list from file text in J2ME - Java BeginnersHow to make a list
from file text in J2ME I was trying to make a method that read
file from text and make a list of it, I have tried ReadHelpText...) {
}
return null; }
kamus.txt
file contains:
iconSebuah lambang kecil berupa gambar
How to extract a specific line from a text file? - IoCHow to extract a specific line
from a
text file? Hi all,
i'm trying to write a code that return a specific line
from a
text file.
so my first...° 100 to 120 for example.
My
Text file contain numbers and words.
How i have
Read Lines from text file read
from the
text file and displays the output as desired. Unable to read the rest...Read Lines
from text file Here's a brief desc of what my Java code does .. I'm using BufferedReader to read lines
from a
text files and split each
How to remove paragraph from ms wordHow to remove paragraph
from ms word Hi! I am using MS
Word to edit my
text but somehow i get paragraph sign on every line of my
text. So, can any one please tell me
how to remove paragraph
from ms
word?
CTRL+SHIFT+8
how to update the text file?how to update the
text file? if my
text file contains a string and integer in each line say,:
aaa 200
bbb 500
ccc 400
i need a java code to update the integer value if my input String matches with the string in
file.
please
binary search tree from text filebinary search tree
from text file
How so I go about constructing a binary search tree
from a
text file, which has letters and numbers, which must be sorted and printed in ascending order.
E.g.
Text file contents
3 apples pears
how to update the text file?how to update the
text file? my textfile with name list.txt:
Rice... i want to update the quantity in my
text file, if the item i entered matches...=new float[n1];
for(int i=0;i
File file ;
FileReader fr=null
Count characters from text file in JavaCount characters
from text file in Java At the "Count chracters fro... is a java code that count the occurrence of each character
from text file.
import... the directory of the
text file ("C:\text.txt").
I use Eclipse to run this code. I
Character from text file - Java BeginnersCharacter
from text file Write a program that reads characters
from a
text file. Your program will count
how many time each character appear in the
text. Assume that the letters are case-sensitive.
Example output
ModuleNotFoundError: No module named 'text-word' '
text-
word'
How to remove the ModuleNotFoundError: No module named '
text...ModuleNotFoundError: No module named '
text-
word' Hi,
My Python... have to install padas library.
You can install
text-
word python with following
ModuleNotFoundError: No module named 'text-word' '
text-
word'
How to remove the ModuleNotFoundError: No module named '
text...ModuleNotFoundError: No module named '
text-
word' Hi,
My Python... have to install padas library.
You can install
text-
word python with following
ModuleNotFoundError: No module named 'text-word' '
text-
word'
How to remove the ModuleNotFoundError: No module named '
text...ModuleNotFoundError: No module named '
text-
word' Hi,
My Python... have to install padas library.
You can install
text-
word python with following
Write records into text file from databaseWrite records into
text file from database
You have already learnt
how to insert records
from text file to database. But here we are going to retrieve records
from database and store the data into the
text file. For this purpose, we have
Problem reading word fileProblem reading
word file Deepak you provide me code for extarcting equation
from a
word file and also to write in a
word file.But when I again want to read preveously created
word file(created by your code) it gives an error
How to handle the text using Key Listener Interface
How to handle the
text using
Key Listener Interface... are going to show you
how to
display the
text of textField1 on the
text field2 on
key... to handle the
text using the
key events
on the Java Awt component. All the
key events
Scanning a word in a TEXT document......Scanning a
word in a
TEXT document...... Hi Genius persons... I'm having many resumes in my FOLDER called HARISH in D:(colon) i want to scan... by searching the JAVA and .net words present in the files..if JAVA
word is present means
Scanning a word in a TEXT document......Scanning a
word in a
TEXT document...... Hi Genius persons... I'm having many resumes in my FOLDER called HARISH in D:(colon) i want to scan... by searching the JAVA and .net words present in the files..if JAVA
word is present means
Count characters from text file in JavaCount characters
from text file Using Java
Here we are going to count the occurrence of each character
from the
text
file. For this, we have used the
BufferedReader class to read the specified
file. Then we have
removed
Removing duplicate white spaces from a text file
Removing duplicate white spaces
from a
text file
... duplicate white
spaces
from a specific
text file. In this section a program is given... spaces
from the
given
text file. This program reads the
file line-by-line for search
How to copy text from a gif imageHow to copy
text from a gif image I have some gif images that containing some important
text. i want to have that
text in my notepad
file. i have.... so, please tell me
how can i copy that
text to my notepad. i am using ubuntu