【问题标题】:how can i use RegExp to detecting duplicated specific input in string variables我如何使用 RegExp 检测字符串变量中重复的特定输入
【发布时间】:2021-12-28 02:29:57
【问题描述】:

飞镖 颤动

我需要正则表达式来知道来自用户输入的字符串变量是否包含超过 1 个相同的输入

我想要处理的想要的输入 (- _ .)

我不会重复多次的想要的输入是 - 或 .或_

假设用户写了Alex.9 .. 听起来不错,因为他写了一个点 好吧,我已经知道如何处理,以防两个点相邻,例如Alex..9 使用contains('..'),但如果这两个点不是像A.le.x那样彼此相邻,结果将是false

我想要的不是和好的:=

Alex.9 => ok
A.le.x => no
Alex-9 => ok
A-le-x9 => no
Alex_9 => ok
Al_e_x9 => no


 // also if there was two or the whole difference  of (- _ .) in the same string. like
 A.le-x => no
 A.le_x => no
 A-l_9 => no
 A.l-x_9 => no

我的意思示例

final TextEditingController nameController = TextEditingController();
Scaffold(
body: nameController.text.contains(RegExp('Is - or _ or . duplicated?'))?
      Text('yes duplicated') : Text('not duplicated'),
);

【问题讨论】:

    标签: regex string flutter dart string-length


    【解决方案1】:

    正则表达式:[._-](.*[._-])+

    【讨论】:

    • 谢谢你 .. 72 小时试图处理这个问题 .. 你刚刚救了我
    猜你喜欢
    • 1970-01-01
    • 2021-06-20
    • 2021-02-25
    • 2021-07-05
    • 2020-11-19
    • 2019-01-20
    • 1970-01-01
    • 2019-08-08
    • 2014-09-30
    相关资源
    最近更新 更多