Answer the question
In order to leave comments, you need to log in
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
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 questionAsk a Question
731 491 924 answers to any question