I'm writing up some documentation, and I'm unsure which phrase to use:

Option X: Find all strings ending with foo.


Option X: Find all strings ending in foo.

Are both correct? (Google spits out both, strongly favoring with.) Which should I prefer?


4 Answers 4


"Ends in" is acceptable in the sense that words can end in a vowel; end in an "a"; etc. This is often shortened to:

"Word" ends in "d"

"Ends with" seems to fulfill the same use:

"Word" ends with "d"

But I typically think of "ends with" using larger things than letters:

"This phrase" ends with "phrase"

"This is a sentence" that ends with "sentence"

Really, though, both "in" and "with" are doable:

"Hungry" and "angry" both end in "gry."

"Hungry" and "angry" both end with "gry."

The only difference I can find is their usage outside of words:

Our journey ends in Texas.

Our journey ends with disaster.

To directly answer your question, both work just fine in the original context. Some people prefer one over the other; some workplaces will have a strict style guide dictating which should be used. At the end of the day, consistency is more important.

As for references, there isn't much to find other than looking at hits via Google. NGram searching for "ends in/with c" shows:

enter image description here

But that really doesn't mean much, given the propensity for quirks in searching algorithms. Just browsing pages found by Google is of virtually no help given how often people use both phrases.

  • What I great and insightful response. It is the best answer I got. I have asked several grammarians about this. Thank you very much.
    – Nikolai
    May 4, 2011 at 22:36
  • our journey ends in Texas is like that because Texas is a place you can be in Sep 19, 2021 at 13:00

Close call. I would say that "in" is asking for a very precise case, whereas "with" is for more general usage. For example:

Which words end in "ces"?


Which words end with a vowel


Both are acceptable. The difference is very subtle and is a matter of style.

end in is a phrasal verb

  • end in [something]
  • end [something] in [something]

end with is a phrasal verb

  • end with [something]
  • end [something] with [something]

Notice that end in has a specific usage "the meeting ends in disaster" to specify the result, while "the meeting ends with disaster" states the sequence of unrelated events, "the show ended with another famous song".

So if there is a logical connection you may use end in like in

Plural usually ends in -s.

This is making a small logical connection between ending -s and something being plural. You have established the cause in both directions.

If you just want to state how a word ends, with has no such connection "elephant ends with -phant". But: "aluminum ends in -um", because other chemical elements end in -um as well.

The difference is really subtle, and is a matter of style.

So in your example, if you really want to be pedantic and follow some common style, you would use in in case "foo" has some particular meaning, otherwise you use with. This is nothing like a rule, just a point into a direction of making difference between the two, showing the logical layer where they may differ.

Find the first file with the name ending in .txt (suggesting it is a recognizable extension, additionally avoiding double with ... with)


I would go with

Option X: Find all strings ending with foo.

It sounds more solid.

  • Thanks. Is "sounds more solid" the opposite of "sounds a bit shaky", or does it imply something else? :-)
    – Martin
    Jan 18, 2011 at 9:33
  • It doesn't mean anything else, I just think that it's more convenient to use with. Personally, I've never seen ending in in technical documentations. That doesn't mean it's wrong, of course. It's up to you. ;) Jan 18, 2011 at 9:50

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.