groups

Scala: How to extract parts of a String that match regex patterns

This is an excerpt from the Scala Cookbook (partially modified for the internet). This is Recipe 1.9, “Extracting Parts of a String that Match Patterns.”

Problem

You want to extract one or more parts of a Scala String that match the regular-expression patterns you specify.

Solution

Define the regular-expression (regex) patterns you want to extract, placing parentheses around them so you can extract them as “regular-expression groups.” First, define the desired pattern:

A Drupal fieldset example (Drupal form group)

Drupal form fieldset FAQ: How do I build a Drupal form using one or more fieldset areas to group my form elements into logical components (like 'shipping address', 'billing address', 'credit card information', and so on)?

As inferred by the question, you group Drupal form elements using the Drupal fieldset element. You define a fieldset, then add form elements to that fieldset using a simple sub-array syntax. For example, in the following Drupal source code example I define a fieldset using an array like this: