• Skip to main content
  • Skip to header right navigation
  • Skip to site footer
CDP Studio logo

CDP Studio

The no-code and full-code software development tool for distributed control systems and HMI

  • Doc
  • Why CDP
    • Software developers
    • Automation engineers
    • Managers
  • Products
    • Automation Designer
    • HMI Designer
    • Maritime HMIs
  • Services
  • Use cases
  • Pricing
  • Try CDP

CDP Studio Documentation

  • Framework - Automation
  • Regex
  • 5.0.0

Regex Class

(Automation::Regex)
Header: #include <Regex>
Inherits: CDPOperator<std::string>
  • List of all members, including inherited members

Public Functions

Regex(const CDPPropertyBase &in)
virtual ~Regex()

Reimplemented Public Functions

virtual bool AddChild(const std::string &name, const std::string &typeName, const std::string &configuration) override
virtual void Configure(XMLPrimitive *operatorXML) override
virtual void Create(const char *pzName, CDPBaseObject *pParent) override
virtual unsigned int Process() override
virtual bool RemoveChild(const std::string &name) override
  • 18 public functions inherited from CDPOperator
  • 17 public functions inherited from CDPOperatorBase
  • 49 public functions inherited from CDPBaseObject
  • 27 public functions inherited from CDP::StudioAPI::CDPNode
  • 22 public functions inherited from CDP::StudioAPI::ICDPNode

Additional Inherited Members

  • 1 public variable inherited from CDPOperatorBase
  • 1 static public member inherited from CDPBaseObject
  • 1 protected function inherited from CDP::StudioAPI::CDPNode
  • 8 protected variables inherited from CDPOperator
  • 5 protected variables inherited from CDPOperatorBase
  • 10 protected variables inherited from CDPBaseObject

Detailed Description

The Regex operator searches substrings from input value using regular expression search pattern.

The Regex operator has the following properties:

PropertyDescription
PatternPOSIX regular expression search pattern to use on In.

Arguments

ArgumentDescription
InThe default input value.
OutThe default output value. The operator bypasses the input value to output without change.
Unlimited number of output argumentsArguments to store the matched block (regex group) values into.

The Regex search pattern is a string that describes the expected input, with special character entities that indicate blocks (groups) that will be copied to output argument values (in the order of occurrence).

Let's assume that an input string like this:

Temperature: 25.1 C; Humidity: 55 %

A Regex operator with the following Pattern can output values to temperature and humidity arguments:

Pattern="Temperature: (\S+) C;\s+Humidity: (\S+) %"

Regex search patterns can detect and copy values from very complex input strings.

Below is a table with the most useful special characters in patterns:

(...)Specifies a block (regex group). Anything that is matched inside parenthesis is copied to value for the next argument in list.
.Matches any character
\.Matches . character (dot)
\sMatches any whitespace character (space, tab or newline)
\SMatches any non-whitespace character (any character except space, tab and newline)
\dMatches any digit character
\DMatches any non-digit character
\wMatches any alphanumeric character (letter, number or underscore)
\WMatches any non-letter character (so it is not a letter, number nor underscore)
+Indicates one or more occurrences of the preceding elements. For example, S+ causes to match one or more sequential non-whitespace characters.
*Indicates zero or more occurrences of the preceding elements. For example, S* causes to match any number (or zero) sequential non-whitespace characters.

You can learn more about regex possibilities, at:

  • Boost regex page
  • Wikipedia regex page

Actual Processing Code of the Evaluate

unsigned int Regex::Process()
{
  m_output = m_input;

  if (static_cast<string>(m_input) != m->cachedInput)
  {
    m->cachedInput = static_cast<string>(m_input);
    if (!m->cachedInput.empty() && m->regexOK)
    {
      boost::smatch matches;
      if (boost::regex_search(m->cachedInput, matches, m->regex))
      {
        size_t index{1};
        for (auto arg : m_arguments)
        {
          auto s = static_cast<std::string>(matches[index]);
          if (index < matches.size())
            *arg = s;
          else
            arg->SetValue(""); // clear all non-matcing arguments
          ++index;
        }
      }
      else
      {
        GetParent()->ReportConfigurationFault(this, "Input '" + m->cachedInput +
                                              "' does not match the configured regex pattern '" +
                                              m->pattern + "'");
        for (auto arg : m_arguments)
          arg->SetValue(""); // clear all arguments on pattern mismatch
        m->faultReported = true;
        return STATUS_SIGNAL_FAULT;
      }
    }
    else
      for (auto arg : m_arguments)
        arg->SetValue("");

    if (m->regexOK && m->faultReported)
    {
      GetParent()->ClearConfigurationFault(this);
      m->faultReported = false;
    }
  }
  return STATUS_OK;
}

See also Argument.

Member Function Documentation

Regex::Regex(const CDPPropertyBase &in)

Default constructs an instance of Regex.

[virtual] Regex::~Regex()

Destroys the instance of Regex. The destructor is virtual.

[override virtual] bool Regex::AddChild(const std::string &name, const std::string &typeName, const std::string &configuration)

[override virtual] void Regex::Configure(XMLPrimitive *operatorXML)

[override virtual] void Regex::Create(const char *pzName, CDPBaseObject *pParent)

[override virtual] unsigned int Regex::Process()

[override virtual] bool Regex::RemoveChild(const std::string &name)

The content of this document is confidential information not to be published without the consent of CDP Technologies AS.

CDP Technologies AS, www.cdpstudio.com

Get started with CDP Studio today

Let us help you take your great ideas and turn them into the products your customer will love.

Try CDP Studio for free
Why CDP Studio?

CDP Technologies AS
Hundsværgata 8,
P.O. Box 144
6001 Ålesund, Norway

Tel: +47 990 80 900
E-mail: info@cdptech.com

Company

About CDP

Contact us

Services

Partners

Blog

Developers

Get started

User manuals

Support

Document download

Release notes

My account

Follow CDP

  • LinkedIn
  • YouTube
  • GitHub

© Copyright 2025 CDP Technologies. Privacy and cookie policy.

Return to top