A
A
alexfyodrv2018-05-04 07:29:33
JavaScript
alexfyodrv, 2018-05-04 07:29:33

How to check for a match at the end of a string?

Tell me how to check if the entry in the string is the last one and if there are no characters after it?
For example, I am looking for the word car in the sentence This is a car and this should return true, and This is a car or something else should return false since there is text further.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
N
Nikolai Dombrovsky, 2018-05-04
@nDiviD

Elementary answer: /(car)$/-for the case when there is nothing at all after the word - characters, spaces, line breaks.
With a line break, but without tabs, spaces: /(car)(?=$|\n)/
MB I misunderstood something from the task.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question