Coding With Fun
Home Docker Django Node.js Articles Python pip guide FAQ Policy

Groovy regular expression


May 14, 2021 Groovy



Regular expressions are patterns used to find substrings in text. Groovy 〜“regex” The text contained in the quotation marks represents the expression used for comparison.

For example, we can create a regular expression object, as follows -

def regex = ~'Groovy'

When Groovy operator =〜 as if in while and while statements (see Chapter 8), the String the regular expression operant on the right. 20> true

When you define a regular expression, you can use the following special characters

  • There are two special position characters that represent the beginning and end of a line: caret (∧) and the dollar sign ($).

  • Regular expressions can also include quantum words. A plus sign, which represents one or more times, is applied to the previous element of the expression. ce. uestion mark (?) ) represents zero or once.

  • Meta-characters , and , are used to match a specific number of instances of the previous character.

  • In regular expressions, the period symbol (. C an represent any character. This is described as a wildcard.

  • Regular expressions can include character classes. A set of characters can be included as a simple sequence of characters in meta-characters, such as aeiou. F or letter or numeric ranges, you can use dash separators in [a-mA-M] [a-z] T he complement of the character class is represented by a leading insertion symbol in square brackets, [∧a-z] and represents all characters except the specified characters. H ere are some examples of regular expressions.

'Groovy' =~ 'Groovy' 
'Groovy' =~ 'oo' 
'Groovy' ==~ 'Groovy' 
'Groovy' ==~ 'oo' 
'Groovy' =~ '∧G' 
'Groovy' =~ 'G$' 
'Groovy' =~ 'Gro*vy' 'Groovy' =~ 'Gro{2}vy'