FreeStyler
FreeStyler

Reputation: 317

Libreoffice Calc REGEX how get second match?

How get second match of REGEX? For example:

A1: 11:33

=REGEX(A1;"\d{2}") - gets 11, but I want 33!

Upvotes: 0

Views: 1475

Answers (2)

sticky bit
sticky bit

Reputation: 37472

You can try to capture the second pair of digits (that's the one after the first) and replace everything with the captured value.

=REGEX(A1,"^.*?\d{2}.*?(\d{2}).*$","$1")

Edit:

From your comment on the other answer it seems like you don't have a string but a time. In that case regex is the wrong tool. Simply use MINUTE() to extract the minute portion of a time:

=MINUTE(A1)

Upvotes: 1

tohuwawohu
tohuwawohu

Reputation: 13618

Answer depends on range of possible input values. Do you always need the last two number characters of the cell's content (paragraph)? If yes, then you could add a $ so that the regex matches just for content at the end of the paragraph (see the documentation):

=REGEX(A1;"\d{2}$")

See the following example (A1='11:33; A2 contains the formula shown in A3 (using the FORMULA() function).

enter image description here

Upvotes: 1

Related Questions