M
M
mr_creo2017-05-31 13:23:48
Perl
mr_creo, 2017-05-31 13:23:48

How to combine two regular expressions?

We have a string, we need to find out whether both templates are included in it, the order of occurrence is not important.
i.e. replace :
if ($str =~/$pattern1/g && $str =~/$pattern2/g)
with something like:
if ($str =~/$pattern1 && $pattern2/g)

Answer the question

In order to leave comments, you need to log in

1 answer(s)
V
vaut, 2017-05-31
@mr_creo

Since I left the answer, I will collect everything from the comments:
1) peeking, they work for a long time: 2) full enumeration, do not add 3rd pattern:
3) does not work if the pattern can occur more than once:
/($pattern1|$pattern2){2}/

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question