B
B
betterthanyouthink2020-02-20 16:24:43
JavaScript
betterthanyouthink, 2020-02-20 16:24:43

How to find two substrings in a string using regex?

Line: I hate regular expressions
I need a regular expression that will look for the words hate and expressions in the given string.
For example, match should return an array of ["hate", "expressions"], or any other method that will return, for example, true if both words are found, or false if not found.

//я пробовал вот так и еще много как (начиная с 10 утра), но так и не получилось :(
let str = 'I hate regular expressions',
            regexp = /hate expressions/gi;

str.match(regexp);

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
Alex, 2020-02-20
@betterthanyouthink

/(hate|expressions)/gi;

M
Michael Aniskin, 2020-03-06
@MichaelAniskin

https://regex101.com/r/AlbcRR/1

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question