Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

正则可以按照需求截取一小段字符的部分吗 #25

Closed
a-big-cutie opened this issue Aug 22, 2019 · 13 comments
Closed

正则可以按照需求截取一小段字符的部分吗 #25

a-big-cutie opened this issue Aug 22, 2019 · 13 comments

Comments

@a-big-cutie
Copy link

将统一社会信用代码进行截取,自倒数第2位数字开始往前共推9位数字。
比如这样: 91110108101966816T ----> 101966816
这样的可以吗 不行只能截取字符串在判断

@any86
Copy link
Owner

any86 commented Aug 22, 2019

image
@hpg-github 是这个意思吗?

@a-big-cutie
Copy link
Author

图片
@ HPG-GitHub的是这个意思吗?

没毛病,好强大的正则,之前一直以为只是校验类的可以。get了

@any86
Copy link
Owner

any86 commented Aug 22, 2019

好用就行, 你先用着, 我稍后再优化优化, 然后收录到网站

'91110108101966816T'.match(/^\d+(\d{9})/)

@a-big-cutie
Copy link
Author

好用就行, 你先用着, 我稍后再优化优化, 然后收录到网站

'91110108101966816T'.match(/^\d+(\d{9})/)

感谢

@any86
Copy link
Owner

any86 commented Aug 22, 2019

@hpg-github 不客气

@any86 any86 closed this as completed Aug 22, 2019
@any86
Copy link
Owner

any86 commented Aug 22, 2019

@hpg-github 最后一位一定是大写字母吗?

@any86
Copy link
Owner

any86 commented Aug 22, 2019

('91110108101966816T').match(/^(?:\d|[A-Z])+((?:\d|[A-Z]){9})(?:\d|[A-Z])$/i)

我有看了看"社会信用代码"的介绍, 你用这个,之前那个不行

@a-big-cutie
Copy link
Author

@hpg-github 最后一位一定是大写字母吗?

我刚刚查了查 ,不一定是大写的英文字母
91210200MA0QE7GT5L 91210200MA0QE7PH40 91210200710931264L
912102316738119081 91210231693282716J 91210200317986672Y
91210200MA0QCLUJXK 难搞啊

@any86
Copy link
Owner

any86 commented Aug 22, 2019

@hpg-github 用这个

('91110108101966816T').match(/^(?:\d|[A-Z])+((?:\d|[A-Z]){9})(?:\d|[A-Z])$/i)[1]

@a-big-cutie
Copy link
Author

('91110108101966816T').match(/^(?:\d|[A-Z])+((?:\d|[A-Z]){9})(?:\d|[A-Z])$/i)

我有看了看"社会信用代码"的介绍, 你用这个? 之前那个不行

你在那学的正则 我也想写,我再试试

@a-big-cutie
Copy link
Author

@hpg-github 用这个

('91110108101966816T').match(/^(?:\d|[A-Z])+((?:\d|[A-Z]){9})(?:\d|[A-Z])$/i)[1]

可以了 ,感谢

@any86
Copy link
Owner

any86 commented Aug 22, 2019

就是看mdn文档, 多写多练, 我也是因为维护这个才用的熟练, 你平时主要工作用正则地方少, 练得少

@a-big-cutie
Copy link
Author

就是看mdn文档, 多写多练, 我也是因为维护这个才用的熟练, 你平时主要工作用正则地方少, 练得少

get了,感谢,平时工作确实不怎么用,找个时间看看。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants