ONLINE HELP
 WINDEVWEBDEV AND WINDEV MOBILE

Help / WLanguage / WLanguage functions / Standard functions / String functions
  • Escape characters
  • Special characters
  • Use a condition in a regular expression
  • Wizard of the MatchRegularExpression function
WINDEV
WindowsLinuxUniversal Windows 10 AppJavaReports and QueriesUser code (UMC)
WEBDEV
WindowsLinuxPHPWEBDEV - Browser code
WINDEV Mobile
AndroidAndroid Widget iPhone/iPadIOS WidgetApple WatchMac CatalystUniversal Windows 10 App
Others
Stored procedures
MatchRegularExpression (Function)
In french: VérifieExpressionRégulière
Warning
From version 27, this function is kept for backward compatibility. It is recommended to use RegexMatch, which uses the ECMAScript lexical grammar for regular expressions.
Checks whether a character string matches a specific format and retrieves the different substrings that match the format. A wizard in the code editor helps you create the format to be checked.
WEBDEV - Browser code MatchRegularExpression uses the syntax of regular expressions available in JavaScript.
Example
WINDEVWEBDEV - Server codeReports and QueriesUniversal Windows 10 AppAndroidAndroid Widget JavaUser code (UMC)PHPAjax
// Check an email address 
IF MatchRegularExpression(MyEmail, "[-.a-z0-9]+[@][-.a-z0-9]+[.][a-z]{2,4}") = True THEN
// "[-.a-z0-9]+": string containing 1 or more characters
// This string can contain letters from 'a' to 'z',
// digits from '0' to '9', and the '-' and '.' symbols
// [.] indicates that this character must correspond to a dot. 
// "[a-z]{2,4}": string containing 2, 3 or 4 characters
// This string can contain letters from 'a' to 'z'
Info("The email address: " + MyEmail + " is correct.")
END
WINDEVWEBDEV - Server codeReports and QueriesUniversal Windows 10 AppUser code (UMC)PHPAjax
// Extract the different elements from a date
// whose format is DD/MM/YYYY (for example: 28/03/2003)
MyDate is string = "28/03/2003"
MyDay, MyMonth, MyYear are strings
IF MatchRegularExpression(MyDate, "([0-9]+)/([0-9]+)/([0-9]+)", ...
MyDay, MyMonth, MyYear) = True THEN
Trace(MyDay, MyMonth, MyYear)
ELSE
Error("The date format is invalid")
END
WINDEVWEBDEV - Server codeReports and QueriesUniversal Windows 10 AppUser code (UMC)PHPAjax
// Extraction variables
ADay is string
AMonth is string
AYear is string
ATime is string
DateToCheck is string = "Tue, 11 Apr 2006 18:25:09 +0200"
IF MatchRegularExpression(DateToCheck, ...
"[A-Za-z]{3,3}[,] ([0-9]{1,2}) ([A-Za-z]{3,3}) " +...
"([0-9]{4,4}) ([0-9]{2,2}[:][0-9]{2,2}[:][0-9]{2,2}) [\+][0-9]{4,4}", ...
ADay, AMonth, AYear, ATime) = False THEN
Info("Invalid date")
ELSE
Info("Valid date", "Day: " + ADay," Month:" + AMonth, "Year: " + AYear, ...
"Time: " + ATime)
END
Syntax

Checking a format Hide the details

<Result> = MatchRegularExpression(<Element to check> , <Regular expression>)
<Result>: Boolean
  • True if the string matches the specified format,
  • False if the string does not match the format.
<Element to check>: Character string
Character string to check. This string must be written in Latin characters.
<Regular expression>: Character string
Reference format, expressed as a regular expression. This string must be written in Latin characters. This format uses the following characters:
A B C - / _Letters and symbols to check.
[A-Z] or [0-9]Interval of letters, digits or symbols to check.
*0 or more symbols to check.
+1 or more symbols to check.
\WChecks for special characters (e.g., &, #, @, etc.).

Remark: The | character defines an "OR" condition.

Checking a format and retrieving the elements that match the format Hide the details

<Result> = MatchRegularExpression(<Element to check> , <Regular expression> , <Variable 1> ... [, <Variable N>])
<Result>: Boolean
  • True if the string matches the specified format,
  • False if the string does not match the format.
<Element to check>: Character string
Character string to check. This string must be written in Latin characters.
<Regular expression>: Character string
Reference format expressed as a regular expression. This string must be written in Latin characters. This format uses the following characters:
A B C - / _Letters and symbols to check.
[A-Z] or [0-9]Interval of letters, digits or symbols to check.
*0 or more symbols to check.
+1 or more symbols to check.
\WChecks for special characters (e.g., &, #, @, etc.).
( )Groups part of an expression together.
{ }Defines the minimum and maximum number of times that the previous expression can occur (e.g., {min, max}).

Remark: The | character defines an "OR" condition.
<Variable 1>: Character string, Integer, etc.
Variable that will be automatically initialized with the value that matches the first part of the <Format>. Each part is defined by the '(' and ')' characters.
<Variable N>: Character string, Integer, etc.
Variable that will be automatically initialized with the value that matches the Nth part of the <Format>. Each part is defined by the '(' and ')' characters.
WINDEVWEBDEV - Server codeReports and QueriesUniversal Windows 10 AppAndroidAndroid Widget iPhone/iPadIOS WidgetApple WatchMac CatalystJavaUser code (UMC)Ajax

Checking a format and retrieving the elements that match the format in an array Hide the details

<Result> = MatchRegularExpression(<Element to check> , <Regular expression> , <Array of strings>)
<Result>: Boolean
  • True if the string matches the specified format,
  • False if the string does not match the format.
<Element to check>: Character string
Character string to check. This string must be written in Latin characters.
<Regular expression>: Character string
Reference format. This string must be written in Latin characters. This format uses the following characters:
A B C - / _Letters and symbols to check.
[A-Z] or [0-9]Interval of letters, digits or symbols to check.
*0 or more symbols to check.
+1 or more symbols to check.
\WChecks for special characters (e.g., &, #, @, etc.).
( )Groups part of an expression together.
{ }Defines the minimum and maximum number of times that the previous expression can occur (e.g., {min, max}).

Remark: The | character defines an "OR" condition.
<Array of strings>: Array
Name of the array to be populated. The different elements of the array will be automatically initialized with the values that match the different parts of the <Format>.
Remarks
WINDEVWEBDEV - Server codeWEBDEV - Browser codeReports and QueriesUniversal Windows 10 AppUser code (UMC)PHPAjax

Escape characters

The escape character is "\". Therefore, to check whether the { character is in the string, the regular expression will be [\{]. This escape character can also be used with the "+" and "*" characters.
When used with W, it allows you to check for special characters (#, &, @, etc.) in the string. Example:
IF NOT MatchRegularExpression(EDT_NoName1, ".*\W.*") THEN
Error("No special character found in the string")
ELSE
Info("The string contains at least one special character")
 
END
WINDEVWEBDEV - Server codeWEBDEV - Browser codeReports and QueriesUniversal Windows 10 AppUser code (UMC)PHPAjax

Special characters

The following characters can also be used in the format:
  • TAB to check for tabs. For example:
    MatchRegularExpression(sString, "1" + TAB + "2")
  • CR to check for line breaks. For example:
    MatchRegularExpression(sString, "1" + CR + "2")
WINDEVWEBDEV - Server codeWEBDEV - Browser codeReports and QueriesUniversal Windows 10 AppUser code (UMC)PHPAjax

Use a condition in a regular expression

The | character defines an "OR" condition.
Therefore, the expression "[0-9]{6,6}[_](OPINION|opinion|MCQ|mcq)[_][0-9]{8,8}" is used to check these two types of expression:
  • 123456_opinion_20120913
  • 123456_CQM_20120913
WINDEVWEBDEV - Server codeWINDEV Mobile

Wizard of the MatchRegularExpression function

MatchRegularExpression allows you to use a function wizard in the code editor. This wizard allows you to:
  • use a preset regular expression. A list of preset regular expressions is available.
  • view the regular expression as a diagram or as a sequence of conditions in a table.
  • create a regular expression. Simply:
    • Select the "Custom" preset expression.
    • Click Parameters.
    • Add the different conditions via the "+" button. The regular expression is built in the "Generated regular expression" field.
      Function wizard
    • Enter the expression to be checked.
    • The Save button allows you to save the regular expression. It will appear in the list of preset regular expressions, preceded by "Custom".
Related Examples:
The regular expressions Unit examples (WINDEV): The regular expressions
[ + ] Using regular expressions with WINDEV.
Two use modes are presented for the regular expressions:
- checking the input format
- checking out different elements while respecting the input format.
This example is also used to search for a word in a string. The search can be case-sensitive or not. Possibility to take into account (or not) the start or end of string, as well as spaces (anywhere in the string, even in the sought word)
The regular expressions Unit examples (WINDEV Mobile): The regular expressions
[ + ] Using regular expressions with WINDEV Mobile.
It presents 2 modes for using the regular expressions:
- check the input format
- check out the different elements that match the input format.
This example is also used to search for a word in a string. The search can be case-sensitive or not. Possibility to take into account (or not) the start or end of string, as well as spaces (anywhere in the string, even in the sought word)
Advanced input mask Unit examples (WINDEV): Advanced input mask
[ + ] Handling the input masks in WINDEV:
- Defining the format of positive/negative number in a numeric edit control
- Defining how negative numbers will be displayed in a numeric edit control
- Defining how the value 0 will be displayed in a numeric edit control
- Using a regular expression to prevent from typing characters other than 1, 2, 3, 4, 5 and 6.
- Using a regular expression to "regulate" the input of a French registration number
Business / UI classification: Neutral code
Component: wd290std.dll
Minimum version required
  • Version 9
This page is also available for…
Comments
Click [Add] to post a comment

Last update: 09/25/2023

Send a report | Local help