开发者

Regex to match 0 to 9 Arabic int

开发者 https://www.devze.com 2023-02-26 05:07 出处:网络
I\'m looking for a regex that will only allow Arabic integers from 0 to 9 (no spaces, decimals, nothing... just numbers 0 to 9). I\'m using it part of replace function, so in reality开发者_JS百科 I wa

I'm looking for a regex that will only allow Arabic integers from 0 to 9 (no spaces, decimals, nothing... just numbers 0 to 9). I'm using it part of replace function, so in reality开发者_JS百科 I want to look for anything that does not fit in the 0 to 9 Arabic int criteria, and remove it.

I'm using the following regex but it leaves spaces, and I'm not sure if it only allows Arabic integers.

[^0-9]+$

Any idea how to modify this?


If you're using a regex to validate a string, your ^ should be outside the square brackets. Having it inside means "find characters that aren't 0 to 9". Having it outside makes it a start anchor.

^[0-9]+$

EDIT: if you're performing a regex replacement, remove the $ so you can remove non-integers that are anywhere in a string:

[^0-9]+
0

精彩评论

暂无评论...
验证码 换一张
取 消