PC SOFT

ONLINE HELP
 WINDEVWEBDEV AND WINDEV MOBILE

Home | Sign in | English EN
  • Escape character
  • Special characters
  • Use a condition in a regular expression
WINDEV
WindowsLinuxUniversal Windows 10 AppJavaReports and QueriesUser code (UMC)
WEBDEV
WindowsLinuxPHPWEBDEV - Browser code
WINDEV Mobile
AndroidAndroid Widget iPhone/iPadApple WatchUniversal Windows 10 AppWindows Mobile
Others
Stored procedures
Checks whether a character string corresponds to a specific format and retrieves the different substrings that constitute the format. A wizard in the code editor helps you create the format to check.
Versions 26 and later
Reports and QueriesAjax This function is kept for backward compatibility. We recommend that you use RegexMatch.
New in version 26
Reports and QueriesAjax This function is kept for backward compatibility. We recommend that you use RegexMatch.
Reports and QueriesAjax This function is kept for backward compatibility. We recommend that you use RegexMatch.
Example
Reports and QueriesJavaUser 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 '1' 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
Reports and QueriesUser 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
Reports and QueriesUser 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 (with quotes)
Character string to check. This character string must be written in Latin characters.
<Regular expression>: Character string (with quotes)
Reference format, expressed as a regular expression. This character 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 whether a special character is found (for example &, #, @, ...).

Remark: The | character is used to define an "OR" condition.

Checking a format and retrieving the elements corresponding to 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 (with quotes)
Character string to check. This character string must be written in Latin characters.
<Regular expression>: Character string (with quotes)
Reference format expressed as a regular expression. This character 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 whether a special character is found (for example &, #, @, ...).
( )Delimit part of the format to extract.
{ }Number of repetitions allowed for the previous expression ({min, max} format).

Remark: The | character is used to define an "OR" condition.
<Variable 1>: Character string, Integer, etc.
Variables that will be automatically initialized with the different parts of the format to extract. Each part is defined by the '(' and ')' characters.
<Variable N>: Character string, Integer, etc.
Variables that will be automatically initialized with the different parts of the format to extract. Each part is defined by the '(' and ')' characters.
Versions 16 and later
Reports and QueriesJavaUser code (UMC)Ajax

Checking a format and retrieving the elements corresponding to 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 (with quotes)
Character string to check. This character string must be written in Latin characters.
<Regular expression>: Character string (with quotes)
Reference format. This character 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 whether a special character is found (for example &, #, @, ...).
( )Delimit part of the format to extract.
{ }Number of repetitions allowed for the previous expression ({min, max} format).

Remark: The | character is used to define an "OR" condition.
<Array of strings>: Array
Name of array to fill. The different elements will be automatically initialized with the different sections of the format to extract.
New in version 16
Reports and QueriesJavaUser code (UMC)Ajax

Checking a format and retrieving the elements corresponding to 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 (with quotes)
Character string to check. This character string must be written in Latin characters.
<Regular expression>: Character string (with quotes)
Reference format. This character 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 whether a special character is found (for example &, #, @, ...).
( )Delimit part of the format to extract.
{ }Number of repetitions allowed for the previous expression ({min, max} format).

Remark: The | character is used to define an "OR" condition.
<Array of strings>: Array
Name of array to fill. The different elements will be automatically initialized with the different sections of the format to extract.
Reports and QueriesJavaUser code (UMC)Ajax

Checking a format and retrieving the elements corresponding to 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 (with quotes)
Character string to check. This character string must be written in Latin characters.
<Regular expression>: Character string (with quotes)
Reference format. This character 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 whether a special character is found (for example &, #, @, ...).
( )Delimit part of the format to extract.
{ }Number of repetitions allowed for the previous expression ({min, max} format).

Remark: The | character is used to define an "OR" condition.
<Array of strings>: Array
Name of array to fill. The different elements will be automatically initialized with the different sections of the format to extract.
Remarks
Reports and QueriesUser code (UMC)PHPAjax

Escape character

The escape character is "\". Therefore, to check whether the { character is found in the string, the regular expression will be [\{]. This escape character can also be used with the "+" and "*" characters.
Used with W, it allows you to check the presence of a special character (#, &, @, ...) 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
Reports and QueriesUser code (UMC)PHPAjax

Special characters

The following characters can also be used in the format:
  • TAB to check the presence of a tabulation. For example:
    MatchRegularExpression(sString, "1" + TAB + "2")
  • CR to check the presence of a Carriage Return. For example:
    MatchRegularExpression(sString, "1" + CR + "2")
Reports and QueriesUser code (UMC)PHPAjax

Use a condition in a regular expression

The | character is used to define 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
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: wd260std.dll
Minimum version required
  • Version 9
This page is also available for…
Comments
Click [Add] to post a comment