Regular Expression to find numbers with same digit

2020-07-23 06:29发布

I have been looking for a regular expression with Google for an hour or so now and can't seem to work this one out :(

If I have a number, say:

2345

and I want to find any other number with the same digits but in a different order, like this:

2345

For example, I match

3245 or 5432 (same digits but different order)

How would I write a regular expression for this?

标签: regex
7条回答
小情绪 Triste *
2楼-- · 2020-07-23 07:22

Put the digits of each number in two arrays, sort the arrays, find out if they hold the same digits at the same indices.

RegExes are not the right tool for this task.

查看更多
登录 后发表回答