Purpose of [^\x20-\x7E] in regular expressions

前端 未结 4 1742
情深已故
情深已故 2020-12-13 18:04
 [^\\x20-\\x7E]

I saw this pattern used for a regular expression in which the goal was to remove non-ascii characters from a string. What does it

4条回答
  •  执念已碎
    2020-12-13 18:18

    The caret (^) inside the brackets [] means "not", and the \x20-\x7E denotes a range of ascii characters, where \x20 (space) is the beginning of the range, and \x7E (~) is the end. It is basically anything that is not a letter, number, or common punctuation.

提交回复
热议问题