简体   繁体   English

查找特定字符串正则表达式

[英]Find particular string Regex

How do I include specific words as a delimiter when I already include them?当我已经包含特定词时,如何将它们包含为分隔符?

Lets say I have a 28 MB TAB-delimited text file (approximately 865,000 records) of the complete transit schedule for the city of Toronto.假设我有一个 28 MB 的 TAB 分隔文本文件(大约 865,000 条记录),其中包含多伦多市的完整交通时间表。

But I also don't want the word "complete" in my result.但我也不希望我的结果中出现“完整”一词。

inLine.useDelimiter("[^a-zA-Z]+");

Should I be doing something like this?我应该做这样的事情吗?
inLine.useDelimiter("[^a-zA-Z]+(complete)");

while (inLine.hasNext()) {
      String word = inLine.next().toLowerCase();
      TreeNode node = bst.findOrInsert(new NodeData(word));
      ListNode p = new ListNode(currentLine);
      p.next = node.data.firstLine;
      node.data.firstLine = p;
}
    
      

You can use the replaceAll method, try this code:您可以使用 replaceAll 方法,试试这段代码:

    String wordToReplace = "complete"; //word that you need to exclude
    String fileContent = "hello and welcome to complete course in java";    
    String result = fileContent.replaceAll(wordToReplace, "");
    System.out.println(result);   

How do I include specific words as a delimiter when I already include them?当我已经包含特定单词时,如何包含它们作为分隔符?

Lets say I have a 28 MB TAB-delimited text file (approximately 865,000 records) of the complete transit schedule for the city of Toronto.假设我有一个 28 MB 的 TAB 分隔文本文件(大约 865,000 条记录),其中包含多伦多市的完整交通时间表。

But I also don't want the word "complete" in my result.但我也不希望结果中出现“完整”一词。

inLine.useDelimiter("[^a-zA-Z]+");

Should I be doing something like this?我应该做这样的事情吗?
inLine.useDelimiter("[^a-zA-Z]+(complete)");

while (inLine.hasNext()) {
      String word = inLine.next().toLowerCase();
      TreeNode node = bst.findOrInsert(new NodeData(word));
      ListNode p = new ListNode(currentLine);
      p.next = node.data.firstLine;
      node.data.firstLine = p;
}
    
      

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM