[英]Replace and transform text using regex
我有一個帶有模式的文本。 並且需要將其轉換為對用戶更具可讀性的文本。
//Rawtext => transformed text
@[John](john@gmail.com), how are you? => @John, how are you?
Good morning @[Doe](doe@gmail.com) => Good morning @Doe.
任何幫助深表感謝。 提前致謝。
注意:與 reactjs 的 react-mentions 包相關
這可能會奏效。
const regex = /@\\[([^\\]]+)\\]\\([^\\)]+\\)/g; console.log('@[John](john@gmail.com), how are you?'.replace(regex, '@$1')); console.log('Good morning @[Doe](doe@gmail.com)'.replace(regex, '@$1'));
這是一種方法:
const re = /\\[(\\w+)\\]|\\(.+\\)/g const a = '@[John](john@gmail.com), how are you?' const b = 'Good morning @[Doe](doe@gmail.com)' const result_A = a.replace(re, '$1') const result_B = b.replace(re, '$1') console.log(result_A) console.log(result_B)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.