I want to ban full-width spaces with regular expressions.

Asked 1 years ago, Updated 1 years ago, 96 views

This is what I'm using now

regex:/^[Ah-anger 1- -a-zA-Z0-9]+$/

Half-width spaces are no longer available, but full-width spaces are not possible.

php regular-expression laravel

2022-09-30 21:43

1 Answers

I have looked into it and it seems that only ASCII ranges can be used directly in php character classes.
It would be good to use the u option for Unicode and set up regular expressions, so I changed it as follows:

Scope of Questions
one-to-one-to-one-to-one-to-one-to-one-to-one-to-one-to-one-to-one-to-one-to-one-to-one-to-one-to-one-to-one. \x{4E00}-\x{9FA0}\x{3041}-\x{3093}\x{30A1}-\x{30F6}\x{30FC}a-zA-Z0-9

Range of Chinese characters (as desired) each 0 -鿿- - <- 00- FF
\x{3005}\x{3007}\x{303b}\x{3400}-\x{9FFF}\x{F900}-\x{FAFF}\x{20000}-\x{2FFFFFF}

$regex='/^[\x{3005}\x{3007}\x{303b}\x{3400}-\x{9FFF}\x{F900}-\x{20000}-\x{2FFFFFF}\x{4E00}-\x{9FA0}\x{3041}-\x{30F6'-ZA};uFC0;]
preg_match($regex,$in,$out);


2022-09-30 21:43

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.