【问题标题】:Regex to ignore special characters and capital letters [duplicate]正则表达式忽略特殊字符和大写字母[重复]
【发布时间】:2021-10-09 01:57:36
【问题描述】:

如果“form-field-message”中存在任何“Const Words”,下面的脚本会将“form-field-conversion”(隐藏字段)的值从“ok”更改为“nok”。

这个代码的问题是它只检测每个单词的原样,没有变化。

我需要帮助才能使此代码接受大写字母和特殊字符。我不想写“课程”、“课程”、“课程”,而只想写“课程”并涵盖所有变体(如课程、课程、课程、课程...)。

你能帮帮我吗?

<script>
new BulldeskIntegration({
token: '123456',
map: {
'form_fields[identifier]': 'identifier',
'form_fields[name]': 'name',
'form_fields[email]': 'email',
'form_fields[phone]': 'phone',
'form_fields[message]': 'message',
},
mapCallback: function (fields) {
const words = [
'curriculo',
'currículo',
'Curriculo',
'Currículo',
'CURRÍCULO',
'CURRICULO',        
];
const {
value,
} = document.querySelector('#form-field-message');
if (value && new RegExp(words.join("|")).test(value)) {
        jQuery('#form-field-conversion').attr('value', 'nok');
return [];
}
return fields;
}
});
</script>

【问题讨论】:

    标签: jquery regex


    【解决方案1】:

    您似乎需要i 标志(忽略大小写标志)和一个类表达式[] 用于变音符号的变化:

    const text = `
      curriculo
      currículo
      Curriculo
      Currículo
      CURRÍCULO
      CURRICULO
    `;
    
    const re = /curr[ií]culo/ig;
    
    console.log(text.match(re));

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2014-01-29
      • 1970-01-01
      • 2015-06-25
      • 2016-09-11
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多