powershell - 使用 Select-String 在字符串中查找所需的字符串
问题描述
我正在尝试按顺序查找我在 -Pattern 中定义的所有字符串。例如,
$string = "My car is Yellow but my car seat is White. I ate Yellow Banana, Yellow lemon and White peach."
Select-String -inputObject $string -Pattern 'Yellow', 'White'
I want the result to be like this in an array object in the order it finds in the string:
Yellow
White
Yellow
Yellow
White
解决方案
您可以使用该-AllMatches
参数,但在这种情况下它看起来不会同时使用这两种模式。调整模式可能会有所帮助。
($string | Select-String -AllMatches -Pattern 'Yellow|White').Matches.Value
推荐阅读
- tensorflow - 分类交叉熵在 keras 模型训练中作为损失和准确度度量的不同结果
- javascript - Swiper 产品滑块 Laravel jquery
- excel - 计算以“DOT”或“PRO”开头的列中的唯一过滤值
- python - 训练和验证集的图(过拟合?)
- spartacus-storefront - 带有 + 符号的 PLP 构面过滤器对导致错误结果的 URL 进行编码
- javascript - 无法在反应中解析 HOC 中的值
- entity-framework-core - 来自两个不同实体但相同视图模型类的联合
- php - 为什么 CodeIgniter 3 在 localhost 上变慢并且在服务器上正常工作
- python - 甚至在使用 selenium python 抓取数据之前,网页就已关闭
- python - 有没有办法使用 isin() 作为 pandas 数据框中另一列的计算器函数?