First time here? Check out the Help page!

Question-and-Answer Resource for the Building Energy Modeling Community
Get started with the Help page
Ask Your Question
6

Regular Expressions to filter Output:Variable

asked 9 years ago

updated 2 years ago

In the "Key" field of the Output:Variable, is there any way to wildcards (aside from "*" by itself), or even regular expressions?

Output:Variable, *, !- Key Value System Node Temperature, !- Variable Name hourly; !- Reporting Frequency

For example, I might want to output the System Node Temperature only for all nodes that contain either 'DOAS' or 'DHW'. Is that possible?

Preview: (hide)

Comments

Good question, Unless something has changed I don't think it is possible. But since I don't know I'll just leave this as comment. If using OpenStudio you could enahcne the add output variable measure to search and create multiple 'Output:Variable' objects.

David Goldwasser's avatar David Goldwasser  ( 9 years ago )

2 Answers

Sort by » oldest newest most voted
4

answered 9 years ago

No this is not possible at this point, but it is a great User Voice suggestion. Thanks to @Eric Ringold for finding the spot, you can see in the source code that it only accepts the variable name or "*".

That said, I think adding a true wildcard or regular expression looks possible (on the surface). So add this as a suggestion on User Voice.

Preview: (hide)
link

Comments

Here is the User voice request

Julien Marrec's avatar Julien Marrec  ( 9 years ago )

Are there any examples of using regular expressions for filtering output variables?

kwalkerman's avatar kwalkerman  ( 6 years ago )
1

@kwalkerman: added an answer to update the status of the thread + show examples as you requested. Thanks to @MarkAdams for this really useful feature!

Julien Marrec's avatar Julien Marrec  ( 6 years ago )
7

answered 6 years ago

Support for regular expressions (regex) has been added by @MarkAdams in PR#6017, circa E+ 8.7.

The I/O reference guide shows a simple example of a regex for Key Value here and links to a page showing the Regex flavor that is being used: google/re2.

It also mentions that no regex can contain a comma , even if it is valid regex syntax (eg: between 2 and 5 digits, \d{2,5}, isn't valid).

Even though there isn't support for re2 regex flavor, I strongly recommend https://regex101.com/ as a test bed. It's a website that I wished existed when I got started with regexes, as it allows to quickly test your regex, and will decompose the behavior or a given regex.


Examples

I'll give some fresh examples, because more is better.

If given the following nodes:

SalesFloor InletNode 1
SalesFloor InletNode 2
SalesFloor InletNode 3
Office InletNode 1
Office InletNode 2
Office InletNode 3
SalesFloor OutletNode 1
SalesFloor OutletNode 2
SalesFloor OutletNode 3
Office OutletNode 1
Office OutletNode 2
Office OutletNode 3

Select all SalesFloor's inlet Nodes

SalesFloor InletNode \d+

(\d+ means any digit, one or more, prefer more (=greedy))

Select all SalesFloor's inlet and outlet nodes

SalesFloor (Inlet|Outlet)Node \d+

All Inlet Nodes only

.*InletNode \d+

.* means any character, zero or more times, greedy.

All first two inlet nodes

.*InletNode [1-2]

Select all InletNodes numbered below 100

Typically, you would do .*InletNode \d{1,2}. But like the I/O said, you can't use a comma. So you have to explicitly list the digits here: we want at least one, maybe two, that's it

.*InletNode \d\d*$

I'm not 100% sure the $ = end of text anchor is supported, but I think it is.

It isn't even required here because E+ uses RE2::FullMatch (see here) which requires the regexp to match the entire input text (as opposed to RE2::PartialMatch which looks for a match for a substring of the input text)

Preview: (hide)
link

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Training Workshops

Careers

Question Tools

2 followers

Stats

Asked: 9 years ago

Seen: 603 times

Last updated: Jul 16 '18