regular expressions | Sololearn: Learn to code for FREE!

+1

regular expressions

How to use regular expressions to find such sequences of numbers in the text: "8 9 10" or "10 10 9" or "9 9 8" or "9 8 10"?

4/12/2021 5:37:55 PM

Mary_d9

6 Answers

New Answer

+1

Ok. So, to make sure, for the string 'four 3 8 10 six 9 10 8 8' the correct output would be '8 10', '9 10 8 8' Is that correct? If so, '((?:(?:8|9|10)\s)*(?:8|9|10))' appears to do the trick. Not extensively tested though.

+2

This can be done exactly as you said in the question.

+2

This is a short code for test of your input Mary_d9 with in your question mentioned requested sequences: https://code.sololearn.com/W464rI07K52h/?ref=app

0

Two questions: will there always be 3 numbers, or will the number vary, and what language are you using?

0

Russ The text can contain different numbers and even dates, but I only need 8, 9 and 10. There is a space separator between them. I will execute the command with regex in bash.

0

Russ thank you!