Basically I have this but its either or:
[en].{0,2}$
What I want to do is detect 'en' and not 'e' or 'n'. Just 'en' in that order but in the last three characters.
So it should match
attend
but not:
attained
So it must detect if the last three characters contain 'en' in order.
Just 'en' in that order but in the last three characters.
That means you need to match en
that is either at the end of the string or en
that has any single char after it at the end of the string.
You may use
en.?$
See the regex demo
Details
en
- en
substring .?
- any optional char $
- end of string. If you may have line breaks in the input, use s
modifier: /en.?$/s
.
If you want the last three characters starts with en, You can use this regex
en.$
If you want the last three characters ends with en, You can use this regex
.en$
If both cases are acceptable, You can use this regex
(.en|en.)$
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.