Skip to content

Instantly share code, notes, and snippets.

@c1xf
Created December 17, 2019 08:31
Show Gist options
  • Save c1xf/8716d3a2e23f351a2ba4ae2e80ffea85 to your computer and use it in GitHub Desktop.
Save c1xf/8716d3a2e23f351a2ba4ae2e80ffea85 to your computer and use it in GitHub Desktop.
正则表达式整理
// 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