regexfme

trying to crate a regular expression for string


I have a string like a Taxi:[(h19){h12}], HeavyTruck :[(h19){h12}] wherein I want to keep information before the ":" that is a taxi or heavy truck . can somebody help me with this?


Solution

  • This will capture a single word if it's followed by :[ allowing spaces before and after :.

    [A-Za-z]+(?=\s*:\s*\[)
    

    You'll need to set regex global flag to capture all occurrences.