lundi 17 décembre 2018

Regex matching with pattern and matches

I am reading input from file it contains set of lines as below :

 
    BDI100                 172.20.1.5      YES TFTP   up                    up
    BDI500                 172.20.1.50     YES TFTP   up                    up
    BDI600                 172.20.1.58     YES TFTP   up                    up

I have to extract the complete line which contains only 172.20.1.5

Below is my code :

while ((line = lineNumberReader.readLine()) != null) {
        Pattern p = Pattern.compile(expr.trim()); /*expr is filter contains 172.20.1.5 */
        Matcher m = p.matcher(line);
        if(m.find()){
            System.out.println(line);
        }
    }

I am expexting output as :

BDI100                 172.20.1.5      YES TFTP   up                    up

But it printing

asll

Aucun commentaire:

Enregistrer un commentaire