Using Regular Expressions to Extract a Value in Java

前端 未结 13 1075
失恋的感觉
失恋的感觉 2020-11-22 13:08

I have several strings in the rough form:

[some text] [some number] [some more text]

I want to extract the text in [some number] using the

相关标签:
13条回答
  • 2020-11-22 13:49

    if you are reading from file then this can help you

                  try{
                 InputStream inputStream = (InputStream) mnpMainBean.getUploadedBulk().getInputStream();
                 BufferedReader br = new BufferedReader(new InputStreamReader(inputStream));
                 String line;
                 //Ref:03
                 while ((line = br.readLine()) != null) {
                    if (line.matches("[A-Z],\\d,(\\d*,){2}(\\s*\\d*\\|\\d*:)+")) {
                         String[] splitRecord = line.split(",");
                         //do something
                     }
                     else{
                         br.close();
                         //error
                         return;
                     }
                 }
                    br.close();
    
                 }
             }
             catch (IOException  ioExpception){
                 logger.logDebug("Exception " + ioExpception.getStackTrace());
             }
    
    0 讨论(0)
提交回复
热议问题