通过String中的正则表达式使用斜杠获取正确的日期

时间:2018-04-17 17:37:32

标签: java regex

我有以下字符串volltext

Los 3, PG 3, Lead-Analytiker Anforderungsanalyse / Konzept Servicezeit 1    1   532     7/1/17  10/31/17 

我正在尝试获取行10/31/17中的最后一个字符串。

使用我当前的代码,我得到7/1/17。对我来说很重要 KEYWORDMULTIMATCHPATTERNINFORMATIONSEXTRAKTORZEILENFUELLER结构。我应该如何更改INFORMATIONSEXTRAKTOR正则表达式以获取10/31/17字符串?

这是我的代码:

import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Locale;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

import org.apache.commons.lang3.StringUtils;

public class ZuParser implements BedarfsanforderungParser {

    private static final String KEYWORD = "Los.*PG.*Servicezeit";
    private static final String MULTIMATCHPATTERN = "[\\t\\s]*\\d*[\\t\\s]*\\d*[\\t\\s]*\\d*[\\t\\s]*";
    private static final String INFORMATIONSEXTRAKTOR = "(\\d*[\\/]*\\d*[\\/]*\\d{1,2})";
    private static final String ZEILENFUELLER = "[\\t\\s]*.*";

    private static final Pattern ZUPATTERN = Pattern.compile("^" + KEYWORD + MULTIMATCHPATTERN + INFORMATIONSEXTRAKTOR + ZEILENFUELLER + "$", Pattern.MULTILINE);

    @Override
    public void parse(String volltext, Abruf abruf) {
      // volltext output --> "Los 3, PG 3, Lead-Analytiker Anforderungsanalyse / Konzept Servicezeit 1  1   532     7/1/17  10/31/17"
        fillZu(volltext, abruf);

    }   

    private void fillZu(String volltext, Abruf abruf) {
        String zuDatumstring = getZuDatumString(volltext);

    }


    private String getZuDatumString(String volltext) {  
        Matcher matcher = ZUPATTERN.matcher(volltext);
        if (matcher.find()) {
            String matchString = matcher.group(1);      
            return matchString;
        } else {
            return "";
        }
    }    
}

1 个答案:

答案 0 :(得分:1)

您需要在匹配组之前添加表达式from home import Ui_Home from PyQt5.QtGui import * from PyQt5.QtWidgets import * from PyQt5.QtCore import * class window_home(QMainWindow): def __init__(self, parent=None): QMainWindow.__init__(self, parent) #set up the user interface from Designer self.ui = Ui_Home() self.ui.setupUi(parent) #then do anything as if you were in your output file, for example setting an image for a QLabel named "label" (using QtDesigner) at the root QMainWindow : self.ui.label.setPixmap(QPixmap("./pictures/log.png")) def Home(): f=QMainWindow() c=window_home(f) f.show() r=qApp.exec_() if __name__=="__main__": qApp=QApplication(sys.argv) Home() 以跳过第一个日期:

[\d\/]+\s+