如何在字符串中独立于它们各自的位置匹配两个值 [英] How to match two values independently of their respectiv postions in a string

查看:46
本文介绍了如何在字符串中独立于它们各自的位置匹配两个值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在寻找同时匹配两个值的最佳方法.

I'm searching for the best way to match two values simultaneously.

如果两个值都在一个字符串中,我想得到一个真值,但我不知道它们在字符串中的出现顺序(例如 abcdefbedfa 以防我想匹配 ab)

I'd like to get a true value if both values are in a string but i don't know in which order they appear in the string (e.g. abcdef or bedfa in case i want to match a and b)

是否有比以下更好的解决方案(特别是如果以后我需要更复杂的值来匹配):

Is there a better solution (especially if later I would need more complex values to match) than:

$string =~ m/(a.*b)|(b.*a)/i

推荐答案

$string =~ /a/i && $string =~ /b/i;

这篇关于如何在字符串中独立于它们各自的位置匹配两个值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆