M
M
Michael Compass2021-06-06 01:36:59
Regular Expressions
Michael Compass, 2021-06-06 01:36:59

How to find the 9th space in a text using a regular expression?

For example, there is text:

Пока у Никитушки шел этот разговор с Евгенией Петровной, старуха Абрамовна, рассчитавшись с заспанным дворником за самовар, горницу, овес да сено


We need to find the 9th gap using a regular expression.

How I search for a regular expression for a space:
[\s\S]+(\s{9,9}?)[\s\S]+

But for some reason the 9th space is not found.
What's wrong with regular?

Why do I need this:
Then I will replace the space found using the regular expression with the emoji character using JS.
Since you can stick any other space number I need to replace in the form of a variable into the regulator (but this no longer applies to this thread)

In this example, I described the 9th space number just as an example.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Aetae, 2021-06-06
@mik777em

^\S*(?:\s+\S+){8}(\s)

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question