What is the second to last word in this sentence

I’m looking for a way to match the second last word on a line, such as this:

123 Smith St Melbourne VIC 3000

I’d like to match just «VIC«. Does someone have a regex I can use?

Toto's user avatar

Toto

16.5k50 gold badges29 silver badges41 bronze badges

asked Sep 27, 2018 at 5:24

John's user avatar

2

Depending of what is a «word» for you, you can use:

  • A word is 1 or more characters that is not a space
    • S+(?=h+S+$) will match 1 or more not space followed by 1 or more horizontal space then 1 or more non space
  • A word is 1 or more alphabetic character
    • [a-zA-Z]+(?=h+[a-zA-Z]+$)
  • A word is 1 or more alphanumeric character
    • [a-zA-Z0-9]+(?=h+[a-zA-Z0-9]+$)
  • A word is 1 or more any letter in any language
    • pL+(?=h+pL+$)
  • A word is 1 or more any letter or digit in any language
    • [pLpN]+(?=h+[pLpN]+$)

answered Sep 27, 2018 at 9:22

Toto's user avatar

TotoToto

16.5k50 gold badges29 silver badges41 bronze badges

2

To match the second word from the end use: (?!(w+sw+$))|(?:.+?)

To replace everything other than the second last word use: (?!(w+sw+$))(?:.+?)

You might need to do something about special characters you may have, though.

Worthwelle's user avatar

Worthwelle

4,44811 gold badges19 silver badges31 bronze badges

answered Aug 9, 2019 at 17:29

Bharath Reddy's user avatar

All dictionaries I have looked at give the sole meaning of second to last as next to last (or penultimate and, in BrE, also second last). However, second to last is also used to mean what most folks call the third to last item in a series, especially in technical/scientific usage (see examples below). Can anyone provide documentation of this meaning in a reference work or do dictionaries omit this usage because they judge it to be incorrect (and if so, why not include it with a usage note)? I do not think previous related questions document this meaning adequately.

Related ELU/ELL questions:

«Usage of «second/third/fourth … last»

Are there any differences between «penultimate», «the last but one»
and «second to last»?

«Second-to-last vs second-to-previous»


Dictionaries with second to/from last meaning only next to last or penultmate:

m-w and m-w

Wiktionary

vocabulary.com

Macmillan

last

With the or possessive and an ordinal number. The one(s) the
specified number of places from the end of a series. With of.

The year 1624, the second last of his life, was thus spent by Kin James, in [etc.]
She was the third-last of thirteen children. OED


Examples from Google Books where second to last and next to last are not the same i.e., second to last = third to last (in the usual meaning, or antepenultimate.

Modified Lag Task (Nback)
The task used in the present study was
developed by Shelton et al. (2007). In this task, participants saw
lists of 4 or 6 words and were asked to recall either the last, next
to last (1-back), second to last (2-back)
, or third to last word
(3-back) presented in the list J. T. Shelton, et al.; «A Comparison
of Laboratory and Clinical Working Memory Tests and Their Prediction
of Fluid Intelligence»; Intelligence, May 1, 2009

When the exact number of an instar is not known, it is often
convenient to refer to these with terms such as middle,
antepenultimate (second to last), penultimate (next to last),
and/or ultimate instars. David L. Wagner; Catepillars of Eastern
North America
p.13 (2010)

Accent. For most scientific words, the accent is either on the next
to last syllable or on the second to last syllable
:

a. The accent is on the next to last syllable:
(1) When the word contains only two syllables; algae (AL·gae).

b. In all other cases, the accent is place on the «second» to last
syllable (ar·TI·cul·lus)…

Anthony M. Belmont; Acquiring a Scientific Vocabulary p.23
(2019)

S          second to last hour
T S      next to last hour
U T S  last hour

Gregg DeYoung in Helaine Selin, ed.; Astronomy Across Cultures p. 484 (2021)

Rule C (‘two bounce’ rule). Have at least 3 searches; stop if both the
last quote and the next to the last are larger than the second to
the last
. Peter E. Earl; Behavioural Economics, Vol. 1,
p.168

… the local collections are formed using first, second, and third
window, and second to last, next to last, and last window,
respectively… Genome Research Vol. 14, p.706 (2004)

The cautionary instruction failed to cover the next to last and
second to last prior questions to which responses indeed had been given and which contained the prosecutor’s accusatory statements.
Reports of Cases Decided in the Supreme Court of the State of
Oregon
, p.25 (1996)

Missing values are more common for the next-to-last births and
especially the second-to-last births before… An Assessment of the
Quality of Health Data in DHS-I Surveys
, p.85 (1994)

The first digit gives the number of electrons in the last (outermost)
shell…, the next two digits give the number of electrons in the
next to last shell.., and the final two decimal digits give the number of electrons in the second to last shells… K. B.
Lipkowitz et al. Reviews in Computational Chemistry, Vol. 20,
p.293

(a) Last
(b) Next to last
(c) Second to last
Guide to Port Entry, Vol. 2, p.48 (2001)

As the last stage of this chain of full buffers completes its send
command it waits a time BL before receiving its next token and
unblocking the next to last stage of the chain. This stage then
waits an additional time BL before the next token arrives, and the
receipt of this token unblocks the second to last stage. This
continues until the end of the chain… P. A. Beerel et al. A
Designer’s Guide to Asynchronous VLSI
, p.71 (2010)

…the most weight was placed upon the last stage, followed by next
to last
, second to last, etc. The staging algorithm that we
propose… The application of decomposition to transportation
network
(snippet)

«It doesn’t matter anyway. You
called second to last; I called next to last. That means I go
after you.»
«You’re crazy! Next to last and second to last are the same thing,» Ronny countered fervently.
You’re the crazy one!» Billy shouted, his steel-blue eyes radiating fire.
«It goes last, first to last—that’s the same as next to last— and
then comes second to last

«You always have to have things your own way!» Ronny proclaimed without exaggeration.
Bill Sullivan; Eleven Miles South of Half Moon Bay, p.33

enter image description here
These results are read from the frame F by starting with the
last row of two boxes indicating a 2-cycle, the next to last row of two boxes indicating a second 2-cycle, the second from last
row
of three boxes indicating a 3-cycle, and finally the first row
of four boxes indicating a 4-cycle. S. Keown; An Intoduction to
Group Representation Theory
(1975)

Photo 3 is the last mold; photo 2 next to last; and photo 1
second to last Transactions of the American Society for Steel Treating, p.390 (1924)

Rotation periods
Last ending in 1927 / Next to last / Second to last /
Third to last / Fourth to last
B. Koehler et al.; Effect of Sec, Length of Feeding period…, p. 474 and repeated on p. 475 (1930)

Third from last row added …
Second from last row added …
Next to last row added …
Last row added …
Edward L. Thorndike, «The Curve
of Work» in Psychological Review Vol. 19 (1912)

WORK EXPERIENCE [Form]
Job 1—Last or present position
Job 2—Next to last position
Job 3—Second to last position
N.Y. State Restaurant
Association and E. Curtis; How to Cut Labor Costs, p.21 (1949)

(I’ve also found examples in U.S. and Canadian patents; however, the url links to the Google Book snippets aren’t stable, so I’ve omitted them.)


A fair number of dictionaries don’t have an entry for «second to last,» which may foster to-each-their-own usage. The above examples essentially self-define how the authors are using the expression, even if incorrectly. My own hunch is that some may assume that because there are two well-known expressions, next to last and second to last, they must mean different things. The logic seems to be:

Next to last is considered to be the first from the last (although we don’t usually say this) or penultimate

Second to/from last (Wikitionary has both) is therefore the next item, or the antepenultimate.

———— EDIT 19/13/21 —————

This reasoning is explicitly stated in the first example’s «NBack» Task» added today: next to last (1-back), second to last (2-back), or third to last word (3-back)

Continue Learning about English Language Arts

What is a sentence with the word repetition in it?

The second day was a repetition of the first.


Use the word Auxiliary in a sentence?

Someone second in command is an auxiliary to the person in
charge.


What is a sentence using the word dearth?

The second annual sale was a disappointment, since there was a
dearth of common sizes.


How do you use the word stratosphere in a sentence?

The stratosphere is the second closest layer of the atmosphere
to the earth.
The ozone is in the stratosphere.


What is the accented syllable for the word subject in the sentence ‘Do not subject anyone to ridcule’?

The second syllable is accented.

second to last — перевод на русский

Second to last.

Предпоследний.

And into the second to last corner.

Предпоследний поворот.

Now we’ve got the second to last corner. (Alan) I look like 0live from 0n The Buses.

Предпоследний поворот.

Second to last corner.

Пошевеливайся! Предпоследний поворот.

Here we go. This is, I think, lap number three. Second to last corner, inevitably, and, oh, dear!

Думаю, это третий круг по счету, предпоследний поворот, вот уже, и…

Показать ещё примеры для «предпоследний»…

Отправить комментарий

Complete the second sentence so that it has a similar meaning to the first sentence, using the word given. Do not change the given word. Use between two and four words.
1) My brother Dan learnt this recipe a week ago during the cooking class. (BEEN)
It … a week since my brother Dan learnt this recipe.
2) Skye is planning to have a sightseeing holiday in Rome. It is going to be her first time there. (VISITED)
Skye …Rome yet, so she is planning to have a sightseeing holiday there.
3) The last time Ed was in the gym was two weeks ago. (BEEN)
Ed … to the gym for two weeks.
4) Ice-skating is not as hard for me as roller-skating. (THAN)
As for me, roller-skating … ice-skating.
5) Tommo’s never seen a larger opera theatre in his life. (THE)
This is … opera theatre Tommo has ever seen.
6) Alisha is worse at long-distance running than her classmate. (BAD)
Alisha’s classmate … at long-distance running as she is.

Like this post? Please share to your friends:
  • What is the scottish word for lake
  • What is the sat word of the day
  • What is the same word but different meaning
  • What is the russian word for yesterday
  • What is the russian word for yes and no