我有一个包含名称的列表。有多个同名。我想抓住这些伪骗子的第一个实例并锚定它们。
示例输入
Josh Smith
Josh Smith0928340938
Josh Smith and friends
hello
hello1223
hello and goodbye.
我想要做的是识别 or 的第一次出现,Josh Smith
并在其前面hello
放置一个锚点(例如管道)以进行验证。|
这些也是通配符,因为列表很大,所以我不能专门寻找第一个匹配的Josh Smith
等等。
我想要的输出是这样的:
|Josh Smith
Josh Smith0928340938
Josh Smith and friends
|hello
hello1223
hello and goodbye.
我没有提供任何代码。我对如何解决这个问题有点不知所措,并希望也许有人在使用正则表达式或 Perl 时遇到过类似的情况。