는이
h[\W]*e[\W]*l[\W]*l[\W]*o
같은 것을 사용하지만 많은 문자열을 작성하는 고통스러운 세상에, 읽기 어려워 할 수 있습니다. 당신은 기본 문자열을 구축하고 자신의 정규식 문자열의 자바 스크립트 작성하기 위해 정규식을 사용 할 수 있습니다 당신은 변수 방지를 편집 할 수있는 정규식 개체를 만드는 데 사용하고이
을 일치하는 것을 사용할 수 있습니다
// Pipe delimited list of words, surrounded by parentheses
var rwords = '(howdy|hello|organic)';
// Variable for easy manipulation, sets disallowed characters.
var anti = "[^a-z]*";
// Replace each character with the same followed by the character class contained in the 'anti' variable.
rwords = rwords.replace(/([a-z])/igm,'$1' + anti);
// Surround each side in word boundary markers
rwords = '\\b' + rwords + '\\b';
// Output the regex string as a sample, but you can create a regex object
console.log(rwords);
괜찮은 문자를 담아두기. 숫자를 말하면 '[^ a-z0-9]'로 바꿀 수 있습니다.
"h.l l.o"'(점과 공백이 섞여서) 어떻게해야합니까? 이것도 정규 표현식과 일치해야합니까? –
@ChristianHujer 물론입니다. :) 나는 둘 다했던 정규 표현식을 가질 수 있다고 생각조차하지 못했습니다. –