A
A
Alexey Nikolaev2016-03-24 19:46:58
Programming
Alexey Nikolaev, 2016-03-24 19:46:58

Why does the regex cover one space before a word, even though it's explicitly stated otherwise?

Good evening.
There is such a regular expression, extremely simple. By design, it should cover the actual parts of the string (i.e. all characters that are separated by spaces). To do this, I explicitly specified \S , i.e. everything except spaces and similar characters. However, when triggered, both spaces and letters are covered, although logically this should not be the case. Notably, only the space preceding the word is included in the group (if words are separated by 2 or more spaces, only one of them will be captured).
Where exactly did I go wrong?
Thanks in advance for your advice.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
M
MiiNiPaa, 2016-03-24
@Heian

Your expression:
One non-list character '@', 'p', 'a', 'r', 'a', 'm'
Then some non-whitespace characters.
The space fits into the first category and is captured by the expression. Only one space is captured because one character is captured before "multiple non-whitespace characters"

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question