Created
December 17, 2019 08:31
-
-
Save c1xf/8716d3a2e23f351a2ba4ae2e80ffea85 to your computer and use it in GitHub Desktop.
正则表达式整理
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// bo 解析 | |
const str = ` | |
/** description1 */ | |
valueName1?: string | |
/** description2 */ | |
valueName2: string | |
` | |
const reg = /\/\*\*((?:[^\?\:])+)\*\/\n([^\?\:]+)(?:\?)?\:/g | |
const result =[] | |
let myArray | |
while ((myArray = reg.exec(str)) !== null) { | |
const [,label,value] = myArray | |
result.push({ | |
label:label.trim(), | |
value:value.trim() | |
}) | |
} | |
console.log(result); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment