RegEx: Why start a comma with a comma?

I read how to simulate tree structures in MongoDB and came across in this article , which illustrates a comma-separated path line. In the example, the line starts with a comma, and I was wondering if there was a reason or benefit for this, associated with just a comma after each item in the list?

I marked this post as specific to RegEx, in Java I would not want the comma to start, because I would parse the string in the array using ...

String[] array = string.split(",");

... and in PHP I would use ...

$array = explode(",", $string);

In either of these cases, the beginning of a semicolon will result in an empty string in $array[0].

Thanks in advance!

+4
source share
3 answers

The example does not use a type function split, but it does something that involves viewing characters in a string.

The "protective" leading delimiter is such that if you want to find a single entry aaain:

",zzzaaa,bbb,aaa,zzz"

You can find ,aaa,to avoid false matching zzzaaaif you were looking aaa,.

+2
source

Regular expression is easier to index than conditional execution /^[^,]SomeTopic,*

+2
source

, /,Programming,/. . , , Programming, RegEx.

+1

Source: https://habr.com/ru/post/1524511/


All Articles