Regexes in selection filter

Use this forum to ask questions about how to do things in QCAD.

Moderator: andrew

Forum rules
Always indicate Operating system, QCAD version
Attach Drawing files, Screenshots
Post one question per topic.
Post Reply
User avatar
lphilpot
Full Member
Posts: 72
Joined: Mon Oct 30, 2017 4:03 am
Location: Deep South USA

Regexes in selection filter

Post by lphilpot » Tue Jan 16, 2018 1:21 am

I was reading this topic: viewtopic.php?f=32&t=5360#p19963 where Andrew demonstrated selective selection with the selection filter and a simple regex: "[A-Z]+[0-9]+" (no quotes used in QCAD). I'm not getting the same results, though. I tried it on an existing drawing and after seeing a difference, created a very simple test drawing with the same text he used in that post: ABC123, 123ABC, 123, ABC.

[A-Z]+[0-9]+, [A-Z]+ and [0-9]+ all select everything (all four text entities) -- The purely-numeric "123" is matched by [A-Z]+ and the non-numeric "ABC" is matched by [0-9]+. If I change A-Z to a-z, of course nothing gets selected at all, since this is a case-sensitive regex. Using + instead of * should force the presence of at least one matching character, but it doesn't appear to be happening with the [A-Z]+ and [0-9]+ patterns in my drawing.

Image

I'm no deep expert with regexes in general but this looks pretty straightforward. Why does everything get selected even with or without the alpha/numeric tags? I'm deselecting everything and clicking the Replace Selection button for each test, so that should rule out any previous selection. I even tried a couple of different fonts, but no change. What have I done (or configured?) in this drawing to make QCAD see no difference between alpha/num?

3.19.2 on Xubuntu 16.04, 64-bit

Thanks.
Attachments
Text_selection_test.dwg
(18.05 KiB) Downloaded 23 times
Len
----------------------------------------
QCAD Pro on Xubuntu Linux (usually)

User avatar
andrew
Site Admin
Posts: 5550
Joined: Fri Mar 30, 2007 6:07 am

Re: Regexes in selection filter

Post by andrew » Tue Jan 16, 2018 10:06 am

The regular expression is applied to the source of the text, not only the visible part.

The sources of your (formatted) text entities are:

\H0.125;123ABC
\H0.125;123
\H0.125;ABC123
\H0.125;ABC

The H0 bit matches your regexp.

User avatar
lphilpot
Full Member
Posts: 72
Joined: Mon Oct 30, 2017 4:03 am
Location: Deep South USA

Re: Regexes in selection filter

Post by lphilpot » Tue Jan 16, 2018 1:16 pm

So does that mean it can only be "trusted" to be accurate on non-formatted text? I assumed (?) by changing to the standard (non-TrueType) font it wouldn't have any formatting information. How do we make it work against only the actual textual part of a text label?

By the way, I'm just curious, not critical, since it would seem to seriously impact the usefulness of regex searches (not to mention increase the complexity of regex expressions) if formatting strings have to be taken into account.

Thanks.
Len
----------------------------------------
QCAD Pro on Xubuntu Linux (usually)

User avatar
andrew
Site Admin
Posts: 5550
Joined: Fri Mar 30, 2007 6:07 am

Re: Regexes in selection filter

Post by andrew » Tue Jan 16, 2018 4:28 pm

lphilpot wrote:So does that mean it can only be "trusted" to be accurate on non-formatted text?
It means you can use it not only to look for visible text, but also to look for formatting inside text (which is a good thing :wink: and an important feature). Think selection of all texts containing subscripts or all texts containing italic formatting, etc.

If you want to only look for displayed text (visible text), use the property Plain Text instead of Text.
lphilpot wrote:I assumed (?) by changing to the standard (non-TrueType) font it wouldn't have any formatting information.
No, CAD line fonts have nothing to do with formatting.

If you don't want to use any formatting (line feeds, color changes, subscript, superscript, fat, italic, font changes, etc.), tick simple text in the text dialog or in the property editor. This is recommended for all single line texts without formatting.

User avatar
lphilpot
Full Member
Posts: 72
Joined: Mon Oct 30, 2017 4:03 am
Location: Deep South USA

Re: Regexes in selection filter

Post by lphilpot » Tue Jan 16, 2018 4:42 pm

That makes sense. You don't have to convince me of the usefulness of regular expressions (as I come from a *nix background). :wink:

Thanks.
Len
----------------------------------------
QCAD Pro on Xubuntu Linux (usually)

User avatar
Husky
Moderator/Drawing Help/Testing
Posts: 2094
Joined: Wed May 11, 2011 9:25 am
Location: USA

Re: Regexes in selection filter

Post by Husky » Tue Jan 16, 2018 6:04 pm

lphilpot wrote:... as I come from a *nix background. :wink:
Me too! :shock:
Most of the time I work with the much "less fancy" Find/Replace tool below the Edit menu. Simple is good for me ... :?
Work smart, not hard: QCad Pro

Post Reply

Return to “QCAD 'How Do I' Questions”