Home > OS >  Regex Evaluation
Regex Evaluation

Time:07-25

I'm working with a PowerShell script for which I need to evaluate whether a string contains all of three specific substrings. I don't have foreknowledge of what characters (or the length) may be in between the sub-strings I'm trying to match on. I've tried working with non-capturing groups, but I can't get it to match 'anything' in between the strings, and to still require that all three strings exist, I don't know the right operators to use between the non-capturing groups, or whether I need to use the tempered greedy token (or how to implement that).

Here's an example string that I would want to 'match' the elements below on: file://ringostar.delta.campisi.com/All Files/RAPTOR/Deployment/All/Chaps/Chaps.application#Chaps.application, Culture=neutral, PublicKeyToken=abb52476a21d22b21a, processorArchitecture=x86

Match Conditions (all three must be true):

  1. Starts with: file://
  2. Has somewhere following #1 above (but as you can see not directly adjacent): .delta.campisi.com/
  3. Has this somewhere following #2 above (again not adjacent): Chaps.application#Chaps.application

This is where I'm at (which obviously doesn't work):

^file:\/\/(?:\.delta\.campisi\.com)(?:Chaps\.application\#Chaps\.application)

Suggestions?

CodePudding user response:

You can simply join your three match conditions with .*?, i.e., any character between zero and an unlimited number of times, as few as possible (lazy matching).

Regex:

^file:\/\/.*?\.delta\.campisi\.com\/.*?Chaps\.application#Chaps\.application

Demo:
https://regex101.com/r/muBuEd/1

  • Related