Last active
March 19, 2024 13:40
-
-
Save iwill/a1835fcd38efe6beb20e938e1f80f371 to your computer and use it in GitHub Desktop.
Make RegExp in multiple lines, and indent with white spaces
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
// #see https://stackoverflow.com/a/12317105/456536 | |
RegExp.make = (regExp, opts) => new RegExp(regExp.raw[0].replace(/( #.*|\s)/gm, ""), opts || "") |
Ruby:
reg = /
(
# 声母 + 韵母
([bpmf dtl k jqx yw]?|[zcs]?h?|[ngr]?)
([iu][ao](ng?)|(iao|uai|ve)|i[aue]|u[aoien]|[iuv])
# 可选声母 + 可独立使用的韵母
|([bpmf dtl k jqx yw]?|[zcs]?h?|[ngr]?)?
([aeio](ng?)|a[io]|(ei|ou)|[aoe])
# 只能独立使用的韵母
|er
)
$
/x
Swift:
let reg2nd = #/
(
# 声母 + 韵母
([bpmf dtl k jqx yw]?|[zcs]?h?|[ngr]?)
([iu][ao](ng?)|(iao|uai|ve)|i[aue]|u[aoien]|[iuv])
# 可选声母 + 可独立使用的韵母
| ([bpmf dtl k jqx yw]?|[zcs]?h?|[ngr]?)?
([aeio](ng?)|a[io]|(ei|ou)|[aoe])
# 只能独立使用的韵母
| er
)
$
/#
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Usage: