KICAD8: NetClass Pattern mismatch (Bug or Feature?)

Hi,
I wanted to add nets to a netclass and with the pattern “CLK1_*” KiCad also includes also netname “CLK1”:


Is this an expected behavior or a bug?

Cheers
Hannes

It’s interpreted as a regular expression where * is zero or more of the previous character. CLK1 has zero _ , so it’s a match. For example CLK1_.* might work for you.

Note that KiCad tests both simple pattern match and regular expression match, and if either matches, it’s a match.

1 Like

That means it is a bug via full regex or lazy checks since
CLK1_* should only match CLK1_ CLK_M CLK1_P but it is matching CLK1 as well and thus _ is being ignored

1 Like

Um, do you not understand that * means zero or more occurences?

$ grep 'password_*' /tmp/addr-change-stories.txt
Sometimes reentry of the password or providing a second factor by other means, e.g. SMS.

The _ never comes into play in this match.

But thats the point … it should.

The OP has a pattern request of /DIFF-TRX/CLK1_*
The expectation is it matches
/DIFF-TRX/CLK1_M*
/DIFF-TRX/CLK1_P*

But it is matching
/DIFF-TRX/CLK1
/DIFF-TRX/CLK1_M*
/DIFF-TRX/CLK1_P*

so how is CLK1 being caught when it should be failing because it does not satisfy the minimum of CLK1_

But it does, the minimum is CLK1. The * applies to the previous atom, which is _. Therefore it’s correct for there to be no _ at all.

The strings that CLK1_* matches are:

CLK1
CLK1_
CLK1__

and so forth.

If you had wanted at least one _, then the regex operator you want is +. * = {0,} and + is {1,} occurences.

You may be confused by shell globs which are a kind of regex, but with slightly different meanings for the operators. In a shell glob, * is actually .* in a normal regex.

mmm I guess so…
greedy matching… which means CLK1_+ would be better

If I had a dollar for every time I cursed the classic Unix editor for requiring me to for example use [a-z][a-z]* to find the next word starting with a lower case letter because [a-z]* matches the null string, I’d have retired years earlier. But now vim has implemented +, albeit you have to escape it with \, so [a-z]\+ works.

It matches nothing because it needs the string to end with 1 or more underscore. The regular expression must match the whole string, not only beginning of it.

image

Your string would match only ‘CLK1_’.

But “+” doesn’t work in KiCad it seems :expressionless:

For my specific problem I changed the query to “CLK*_*” because there were also CLK2 and CLK3 which I needed to include, but this only as side information :yum:

See my reply to Naib above.

That works, as a shell glob, meaning “CLK, something, underscore, something”.

KiCad tests it also as a regular expression, but it doesn’t match, because it means “CL, zero or more K, zero or more underscore, end”.

If you want a regular expression, that would probably be CLK._.+ , meaning “CLK, some character once, underscore, any character at least once”.

If this combo of features frustrates y’all the way it does me, consider giving this issue a thumbs up on Gitlab:

1 Like