user1903439
user1903439

Reputation: 2001

Regular expressions handling

I want to write a regular expression that can match the following strings:

OFF
ON
String
Valve

I was thinking to write ^(?<arrivingString>[a-zA-Z]{?})$.

Now I don't know what to write within the curly brackets, as the value of arriving string is different and random.

Thanks

Upvotes: 0

Views: 83

Answers (1)

Tobsey
Tobsey

Reputation: 3400

^(?<arrivingString>(OFF|ON|String|Valve)).*

This matches those 4 words only provided:

  • Mutiline is enabled for the Regex
  • The words are at the start of each line

This Regex will match every line in it's entirety provided it starts with any of those 4 strings. The captured group arrivingStringwill contain whichever of the four words was found.

Upvotes: 2

Related Questions