필터 지우기
필터 지우기

How to use Unicode numeric values in regexprep?

조회 수: 1 (최근 30일)
Vlad Atanasiu
Vlad Atanasiu 2024년 3월 28일
답변: Stephen23 2024년 3월 28일
How can "Häagen-Dasz" be converted to "Haagen-Dasz" using Uincode numeric values? For example,
regexprep('Häagen-Dasz','ä','A')
works fine, but
regexprep('Häagen-Dasz','\x{C4}','a')
does not. Here, the hexadecimal \x{C4} stands for [latin capital letter a] with diaeresis, i.e. [ä].

채택된 답변

Yash
Yash 2024년 3월 28일
편집: Yash 2024년 3월 28일
Hi Vlad,
'\x{C4}' represents the Unicode character Ä (Latin Capital Letter A with Diaeresis) in hexadecimal notation.
If you want to replace ä (Latin Small Letter A with Diaeresis), you should use \x{E4}, which is its Unicode hexadecimal representation.
In the context of your question, you're looking to replace ä with a. The correct approach would be to use the Unicode numeric value for ä in the regex and replace it with a. Here is the code:
regexprep('Häagen-Dasz','\x{E4}','a')
ans = 'Haagen-Dasz'
Hope this helps!

추가 답변 (2개)

Stephen23
Stephen23 2024년 3월 28일
inp = 'Häagen-Dasz';
baz = @(v)char(v(1)); % only need the first decomposed character.
out = arrayfun(@(c)baz(py.unicodedata.normalize('NFKD',c)),inp) % remove diacritics.
out = 'Haagen-Dasz'
Read more:
https://docs.python.org/3/library/unicodedata.html
https://stackoverflow.com/questions/16467479/normalizing-unicode

VBBV
VBBV 2024년 3월 28일
regexprep('Häagen-Dasz','ä','A')
ans = 'HAagen-Dasz'
regexprep('Häagen-Dasz','ä','\x{C4}')
ans = 'HÄagen-Dasz'
  댓글 수: 2
VBBV
VBBV 2024년 3월 28일
이동: VBBV 2024년 3월 28일
regexprep('Häagen-Dasz','\x{e4}','a')
ans = 'Haagen-Dasz'
VBBV
VBBV 2024년 3월 28일
The unicode character for small a is \x{e4}

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Text Data Preparation에 대해 자세히 알아보기

제품

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by