How to a space between Chinese characters and latin, half punctuation characters?

This is my first post here. :slight_smile: Thanks KM, My everyday Mac became so magical and powerful.

I quite enjoy figuring out Regex and experimenting macros by myself. However, I really need some help with this one.

It is a common practice that when process text with Asian characters and English add a space in between. There is a term called Pangu Space. There are many resources available for developers’ tools like Atom, vim… etc., but I want to make it a simple KM micro. I think this can have a huge impact.

Goal: In any text input area, select as many paragraphs of texts and execute the macro, it will cut, process the text with space and paste.

中文的英文叫English。English 的中文叫做英文。123!的中文唸法是1-2-3驚嘆號。
中文的英文叫 English。English 的中文叫做英文。123! 的中文唸法是 1-2-3 驚嘆號。

It has many programing languages like: JavaScript, Go, Objective-C, Ruby, PHP with original codes. But I can’t figure out how to use the regex lines in KM. There are so many.

More about 盤古之白:

Thanks in advance.

Here you go. Two passes with a fairly simple regex pattern (one to check for Chinese, then Latin, the other to check for Latin, then Chinese) should do the trick:

Add Space Between Latin and Chinese Characters.kmmacros (2.3 KB)
35 AM


:star_struck: Thank you so much!
Browsing the code on GitHub, I thought it would require many sets of regex. It is much simpler than what I expected.

Seeing your code I can actually understand how it works. Awesome! Thank you, @gglick. :grinning:

1 Like

Do you use GitHub? If you do, please consider to add your KM macro to the main project on Github. It will help more people and may help more people to know about KM. :grin:

I’m afraid I don’t use GitHub, so if you think my simple macro would really be that useful, feel free to go ahead and add it to the project.

Hi @gglick , your macro works perfectly in my case. Can you please explain more? What is $1 and $2? How do you know these token? I'm not a programmer, only a KM fan. You must know more than the macro help document can tell.
How to get this kind of knowledge about this macro --search and replace Using regular expression ??