Is regex case insensitivity slower?

前端 未结 3 1038
闹比i
闹比i 2021-01-04 03:18

Source

RegexOptions.IgnoreCase is more expensive than I would have thought (eg, should be barely measurable)

Assuming that this

3条回答
  •  情深已故
    2021-01-04 03:52

    If you can tolerate having numbers and underscores in that regex, you can e.g. use the \w modifier (Perl syntax). I believe some engines support [:alpha:], but that is not pure Perl. \w takes into account the locale you are in, and matches both uppercase and lowercase, and I bet it is faster than using [A-Z] while ignoring case.

提交回复
热议问题