Regular expression to allow alphanumeric, max one space etc

后端 未结 2 1571
不思量自难忘°
不思量自难忘° 2021-01-24 22:49

I\'m opening this thread that is really similar to another one but I cannot figure out an issue : I have an input field that allow a alphanumeric string with an optional unique

2条回答
  •  野趣味
    野趣味 (楼主)
    2021-01-24 23:14

    This is a simpler regex using \w (word class):

    ^([\w]+(\s*))$
    

    Test

    It's instantaneous in JavaSript

    var input = "dzdff5464zdiophjazdioj ttttttttt zoddzdffdziophjazdioj ttttttttt  zoddzdffdzdff ttttt zoddzdfff ttttt zoddzdfff ttttt zoddzdfff ttttt  zoddzdfff ttttt zoddzdfff ttttt zoddzdfff ttttt zoddzdfff ttttt  zoddzdfff ttttt zo999  ddzdfff ttttt zoddzdfff ttttt zoddzdff";
    
    var re = /([\w]+(\s*))/g;
    
    console.log(input.replace(re, "boo"));
    

提交回复
热议问题