- android - RelativeLayout 背景可绘制重叠内容
- android - 如何链接 cpufeatures lib 以获取 native android 库?
- java - OnItemClickListener 不起作用,但 OnLongItemClickListener 在自定义 ListView 中起作用
- java - Android 文件转字符串
我需要在字符串中找到特定的文本部分。该文本需要:
K9X6 6GM6 LM11
)this
这样的词, line
, spod
不应该被认可
所以我以这段代码结束:
preg_match_all("/(?<!\S)(?i:[a-z\d]{4}|[a-z\d]{12})(?!\S)/", $input_lines, $output_array);
但它不适用于所有要求。我当然可以用preg_repace
或 str_replace
并删除所有 (!,?,#) 并在循环中计数数字(如果有 4 个或更多)但我想知道是否可以使用 preg_match_all
...
这里是要搜索的字符串:
?K9X6 6GM6 LM11 // not recognized - but it should be
!K9X6 6GM6 LM11 // not recognized - but it should be
K0X6 0GM7 LM12! // not recognized - but it should be
K1X6 1GM8 LM13@ // not recognized - but it should be
K2X6 2GM9 LM14? // not recognized - but it should be
K3X6 3GM0 LM15# // not recognized - but it should be
K4X6 4GM1 LM16* // not recognized - but it should be
K5X65GM2LM17
bla bla bla
this shouldn't be visible
spod also shouldn't be visible
but line below should be!!
K9X66GM6LM11! (see that "!" at the end? Help me with this)
正确 preg_match_all
应该返回这个:
K9X6
6GM6
LM11
K9X6
6GM6
LM11
K0X6
0GM7
LM12
K1X6
1GM8
LM13
K2X6
2GM9
LM14
K3X6
3GM0
LM15
K4X6
4GM1
LM16
K5X65GM2LM17
K9X66GM6LM11
最佳答案
以下应该可以解决问题:
\b(?:(?=.{0,3}?\d)[A-Za-z\d]{4}\s??){3}\b
[A-Za-z\d]{4}
匹配 4 个字母/数字(?=.{0,3}?\d)
检查这 4 个字符中是否有数字\s??
匹配空白字符,但尽可能不匹配它\b
确保所有内容都不包含在更大的词中请注意,这将允许像 K2X6 2GM9LM14
这样的字符串,我不确定您是否希望这些匹配。
关于PHP - preg_match_all - 有点高级,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31087353/
我对 Powershell 很陌生,正在设置我的 profile.ps1 文件。我有一些托管 DLL,我经常使用它们来维护全天的进程,我希望能够通过快速函数调用加载它们。所以我在我的 ps1 文件中创
实际上我正在处理让我的代码在 IE 中运行的问题。不幸的是这仍然是必要的。 不受支持的方法的 Polyfill 工作正常。但我想知道,如何/是否可以使“const”和“let”起作用。有什么办法可以做
我有一个按钮,它将 window.location 设置为一个 php 文件,该文件生成一个提要,然后下载该提要。但是,由于文件的大小因放入提要的数据而异,有时从单击按钮到弹出文件对话框可能需要一段时
在 iOS 中获取以下内容的最佳方式是什么: 3 个按钮 (?),点击后会更改显示的信息。我有一些想法,但我想听听有经验的人的意见。我问的是如何获得它的外观,最好是一个接一个地使用按钮吗?如果是的话,
int trees = 3; int tree_x, tree_y; for(int r = 0; r 0) { tree_x = random() % m_townsize;
我看过很多关于 C++ 工厂的帖子,但到目前为止我还没有看到解决我的问题的解决方案。 (虽然我可能遗漏了一些东西。) 示例控制台应用程序: #include #include #include
因此,我在 中有 X 幅图像要垂直居中(下面 jquery 中的类名是实际的 )。这工作得很好但是......它只采用第一个值并将其应用于其余图像,导致第一个居中而其他不居中。 我可能会补充一
好吧,正如您可能看出来的那样,我很难想出一个标题。无论如何,我需要从数据库中选择 5 个项目,不包括第一个项目。更具体地说,我在数据库中有项目,每个项目都有一个特定的、自动递增的 ID。我需要选择 I
给定一个项目数组,每个项目都有一个值和成本,什么是最好的算法来确定达到最小值所需的项目最低成本? 例如: Item: Value -> Cost ------------------- A 2
所以,如果你尝试像这样做一个嵌套类: //nestedtest.php class nestedTest{ function test(){ class E extends
是否可以仅深拷贝特定类型的对象,例如列表、字典或元组 示例:[[1, ], ] 我想深度复制第一个列表(当然还有.. 1),但不是SomeObj或 OtherObj .那些应该作为引用。 是否可以使用
跳至上次编辑 我有一个 Person 对象列表,我需要使用 randomize_pairs 函数将它们随机配对,每个 Person 对象都有一个属性目标他们与谁配对。 我的限制是没有人可以与自己配对(
最好用 ruby,但逻辑就足够了...... 考虑到一周是非标准的,我需要一年中的周数。因此,假设您将一周定义为周六 -> 周五。那么,给定一个日期,它是第几周 (1-52)? strftime
这个问题不太可能对任何 future 的访客有帮助;它只与一个较小的地理区域、一个特定的时间点或一个非常狭窄的情况相关,通常不适用于全世界的互联网受众。如需帮助使此问题更广泛适用,visit the
我有这样的模式规则: $(BIN_DIR)/%: $(SOURCES_DIR)/%/*.c $(CC) $? $(CFLAGS) $(LDFLAGS) -o $@ $(LDLIBS) $(LI
CREATE DATABASE 'some database name' ; 使用 mysql 客户端按预期工作。 来自 php/mysqli 的相同查询(不同的数据库名称)- 有点失败。它写入 IN
我有一个 iPhone 应用程序,它本质上是一个列表。顶部有一个 UINavigationBar,然后有一个保存列表的 UITableView。我希望以某种方式提供一个选项,允许用户以不同的方式对列表
我的客户想要的可能实际上是不可能的 - 他们想要一个不裁剪并保留其尺寸的全屏背景图像。他们愿意接受空白,但他们希望图像尽可能地填满屏幕,而不在任何轴上裁剪。我能够找到很好的脚本来实现真正的整页背景,但
我有两个表:文章和文章标签 articles: id, author, date_time, article_text articletags: id, tag (article.id == arti
我正在开发一个模拟器,供应商可以在其中创建由消费者购买的报价。 提供商将报价放在价格(y 轴)x 质量(x 轴)平面上。 消费者只会购买价格低于他们偏好但质量更高的商品 消费者购买具有最大欧氏距离的商
我是一名优秀的程序员,十分优秀!