Reputation: 2544
I am looking for a regex to match the following strings:
node-primary-backup-2017-08-10-15
node-secondary-backup-2017-06-12-32
node-secondary-backup-2017-08-11-24
node-primary-backup-2017-07-13-02
...
I tried the following, but it's not working:
node-(?=primary|secondary)-backup-\d+-\d+-\d+-\d+
Any help is appreciated!
Upvotes: 2
Views: 49
Reputation: 424983
The expression (?=primary|secondary)
is a look ahead, which asserts that the characters immediately following the current position match the specified expression, but it does not consume any input.
Your expression requires that -backup-\d+-\d+-\d+-\d+
matches (primary|secondary)
, which of course is impossible.
Just remove ?=
to make it a simple alternation expression:
node-(primary|secondary)-backup-\d+-\d+-\d+-\d+
Upvotes: 3