regex - 正则表达式在 ios 上提取捆绑 ID
问题描述
我正在尝试使用以下正则表达式从 ios 中提取捆绑 ID:
^\w+(\.\w+)+
它适用于大多数情况,但在其他情况下失败。
例如使用以下包名称:
com.walmartmexico.WalmartMG
com.adobe.Adobe-Reader
com.instacart
gnustos.my.app.com.foo89.app.my.long.package.name.is.very.long
org.freevpn.vpn
com.adobe.scan.ios
com.adobe.Adobe-Reader
fontskeyboard.fonts
co.9count.wink
biser.stories
com.ephedra-software.StackOv
de.barbaraherold.freiheit
它没有完全捕获那些有连字符的:
com.ephedra-software.StackOv
com.adobe.Adobe-Reader
任何想法如何更改我的上述正则表达式以包含上述内容。
解决方案
我会使用:
^\w+(?:[.-]\w+)*$
演示
解释:
^ from the start of the input
\w+ match one or more word characters
(?: followed by
[.-] dot or hyphen separator
\w+ one or more word characters
)* subsequent terms zero or more times
$ end of the input
推荐阅读
- facebook - MVC5 Facebook 身份验证 - 帐户/ExternalLoginCallback?error=access_denied#_=_
- ios - 应用程序运行时无法将蓝牙耳机与 AVAudioSessionCategoryPlayAndRecord 连接
- python-3.x - networkx 和 dict_values 导致浮点参数错误
- java - 通过代码将图像加载到 imageview 将不会加载,除非我之前通过 xml 将图像提供给 imageview
- discord.py - 与python不和谐的日期和时间错误
- java - 如何在 .NET 和 android 之间共享大文件
- angular - Angular 6 错误:无法从伪造的异步测试中生成 XHR。请求网址:https://mlj0xk2yy.com/latest/static/videos
- node-sass - node-sass 在所有项目中缺少供应商文件夹
- jquery - 我如何遍历html表单并单独获取后代
- c++ - 为什么 clang 拒绝这个 unordered_set 定义 gcc 接受?