정규표현식 잘 아시는 분 계실까요?

만약에

Now is the time for all good people to come to the aid of the party

라는 문장이 있다면,

정확히 4글자인 단어를 아래와 같이 ****로 치환하고 싶습니다.

=> Now is the **** for all **** people to **** to the aid of the party



var sentence = Console.ReadLine();
var test = Regex.Replace(sentence, @"[a-zA-Z]{4}", "****");
Console.WriteLine(test);

위의 코드로는

=> Now is the **** for all **** ****le to **** to the aid of the ****y

이렇게 나옵니다.

2개의 좋아요

정규표현식을

"\b[a-zA-Z]{4}\b"

로 바꾸시면 될겁니다.

4개의 좋아요

아 저렇게 하면 되는군요.
정말 감사드립니다.

3개의 좋아요