P
P
PageUp2020-01-31 13:38:33
Qt
PageUp, 2020-01-31 13:38:33

Regular expressions. How to count the number of values ​​separated by a character?

Hello. I'm not very good at regular expressions. I do not understand them and get confused in these patterns. I read the manuals, and now I'm even more confused.

In general, you need to somehow calculate the number of values ​​\u200b\u200bthat are separated in a cell by a comma.

Actually, I wrote like this, but I don’t know how to determine and where to enter a comma so that it is not taken into account but considered a separator. And the variable $xR given eventually acquired a value equal to the number of occurrences, separated by a comma.

$xR = preg_match_all("/(\w+)\/",$data_point[2],$regD);


The cells in which the search is performed look something like this: ma,le,do,

That is, in this case, $xR should become 3.

If it were: ma,le,

$xR should become 2.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
I
Ighor July, 2019-05-09
@Pbalordorbaor

Call qmake -projectin the project folder.
Explanation : source files must be included in the pro file, above command adds/corrects source paths automatically.
Perhaps you need to install packages gcc , g++ , clang

K
KraydenSharp, 2020-01-31
@PageUp

There is such a way.

$xR = preg_match_all("/[^,]+/",$data_point[2],$regD);

In this case, empty values ​​will not be taken into account.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question