正则表达式:数字后跟一个字符

时间:2019-03-28 00:16:17

标签: java regex javafx

我正在尝试创建一个正则表达式,该文本只允许在文本字段中的每个数字之后仅允许数字后跟一个字符

需要匹配的正则表达式-\ d * \ + {1}

不匹配的正则表达式-[^ \ d * \ +){1}]将替换为“”(删除所有其他内容)

final String regexFinalInteger = "\\d*\\+{1}";

    numberElements.textProperty().addListener((observable, oldValueE, newValueE) -> {
        if (!newValueE.matches(regexFinalInteger)) {
            numberElements.setText(newValueE.replaceAll("[^\\d*\\+){1}]", ""));
        }
    });

我期望输出为122 + 1 + 3,但实际输出可以为1 ++ 2 +++ 4 + 123(多个+)

1 个答案:

答案 0 :(得分:0)

如果我的理解正确,您只想用一个替换多个.popup { display: block; position: fixed; left: 20%; right: 20%; top: 20%; bottom: 20%; box-shadow:0px 2px 6px rgba(0,0,0,1); border-radius:3px; color: orange; border: 3px solid orange; border-radius: 10px; background: rgba(0, 0, 0, 0.8); font-size: 4vh; overflow: hidden; } .popup-inner { position: absolute; width: 96%; height: 96%; padding: 2%; overflow: auto; } .popup-close { color: white; }

我相信这会满足您的需求:

<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.2.0/jquery.min.js"></script>
<div class="popup" data-popup="popup-1">
  <div class="popup-inner"> 
    <p>
      <table>
        <tr>
          <td>Title</td><td>Lorem ipsum dolor sit amet, ut vim clita iracundia, sit alia signiferumque at. Te paulo tempor option cum, vero posse iuvaret has ex, quo e</td><td>Date</td>
        </tr>	
        <tr>
          <td>Title</td><td>Lorem ipsum dolor sit amet, ut vim clita iracundia, sit alia signiferumque at. Te paulo tempor option cum, vero posse iuvaret has ex, quo e</td><td>Date</td>
        </tr>
        <tr>
          <td>Title</td><td>Lorem ipsum dolor sit amet, ut vim clita iracundia, sit alia signiferumque at. Te paulo tempor option cum, vero posse iuvaret has ex, quo e</td><td>Date</td>
        </tr>
      </table>
    </p>
    <!-- <p><a data-popup-close="popup-1" href="#">Close</a></p> -->
    <a class="popup-close" data-popup-close="popup-1" href="#">Close</a> 
  </div>
</div>

那是我的第一个Java程序,很抱歉它冒犯了某人。