PC SOFT

ONLINE HELP
FOR WINDEV, WEBDEV AND WINDEV MOBILE

Home | Sign in | English US

  • Escape character
  • Special characters
  • Use a condition in a regular expression
  • Wizard for the MatchRegularExpression function
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
MatchRegularExpression (Function)
In French: VérifieExpressionRégulière
Checks whether a character string corresponds to a specific format and retrieves the different sub-strings that constitute the format. A wizard in the code editor helps you create the format to check.
AndroidAndroid Widget Java In this version, you cannot retrieve the different sub-strings that constitute the format.
WEBDEV - Browser code MatchRegularExpression is using the syntax of regular expressions available in Javascript.
Versions 15 and later
Android This function is now available for the Android applications.
New in version 15
Android This function is now available for the Android applications.
Android This function is now available for the Android applications.
Versions 17 and later
iPhone/iPad This function is now available for the iPhone/iPad applications.
New in version 17
iPhone/iPad This function is now available for the iPhone/iPad applications.
iPhone/iPad This function is now available for the iPhone/iPad applications.
Versions 18 and later
Android Widget This function is now available in Android Widget mode.
Universal Windows 10 App This function is now available in Windows Store apps mode.
New in version 18
Android Widget This function is now available in Android Widget mode.
Universal Windows 10 App This function is now available in Windows Store apps mode.
Android Widget This function is now available in Android Widget mode.
Universal Windows 10 App This function is now available in Windows Store apps mode.
Versions 21 and later
Universal Windows 10 App This function is now available in Universal Windows 10 App mode.
New in version 21
Universal Windows 10 App This function is now available in Universal Windows 10 App mode.
Universal Windows 10 App This function is now available in Universal Windows 10 App mode.
Example
WINDEVWEBDEV - Server codeReports and QueriesAndroidAndroid Widget Windows MobileUniversal Windows 10 AppJavaPHPAjaxUser code (UMC)
// 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
WINDEVWEBDEV - Server codeReports and QueriesWindows MobileUniversal Windows 10 AppPHPAjaxUser code (UMC)
// 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 QueriesWindows MobileUniversal Windows 10 AppPHPAjaxUser code (UMC)
// 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 is using 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 &, #, @, ...).
Note: 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(<Expression to Check> , <Format> , <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 is using 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).
Note: The | character is used to define an "OR" condition.
<Variable 1>: Character string, Integer, ...
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, ...
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
WINDEVWEBDEV - Server codeReports and QueriesAndroidAndroid Widget iPhone/iPadWindows MobileUniversal Windows 10 AppJavaAjaxUser code (UMC)

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 is using 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).
Note: 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
WINDEVWEBDEV - Server codeReports and QueriesAndroidAndroid Widget iPhone/iPadWindows MobileUniversal Windows 10 AppJavaAjaxUser code (UMC)

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 is using 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).
Note: 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.
WINDEVWEBDEV - Server codeReports and QueriesAndroidAndroid Widget iPhone/iPadWindows MobileUniversal Windows 10 AppJavaAjaxUser code (UMC)

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 is using 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).
Note: 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
WINDEVWEBDEV - Server codeWEBDEV - Browser codeReports and QueriesWindows MobileUniversal Windows 10 AppPHPAjaxUser code (UMC)

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
WINDEVWEBDEV - Server codeWEBDEV - Browser codeReports and QueriesWindows MobileUniversal Windows 10 AppPHPAjaxUser code (UMC)

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")
WINDEVWEBDEV - Server codeWEBDEV - Browser codeReports and QueriesWindows MobileUniversal Windows 10 AppPHPAjaxUser code (UMC)

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
WINDEVWEBDEV - Server codeWINDEV Mobile
Versions 22 and later

Wizard for the MatchRegularExpression function

MatchRegularExpression allows you to use a feature wizard in the code editor. This wizard allows you to:
  • use a preset regular expression. A list of preset regular expressions is proposed.
  • view the regular expression as diagram or as sequence of conditions in a table.
  • create a regular expression. You must:
    • Select the preset expression "None".
    • Click the button.
    • Add the different conditions via the "+" button. The regular expression is built in the "Generated regular expression" control.
    • Type the expression to check.
    • The button is used to save the regular expression. It will be proposed in the list of preset regular expressions, prefixed by "Custom".
New in version 22

Wizard for the MatchRegularExpression function

MatchRegularExpression allows you to use a feature wizard in the code editor. This wizard allows you to:
  • use a preset regular expression. A list of preset regular expressions is proposed.
  • view the regular expression as diagram or as sequence of conditions in a table.
  • create a regular expression. You must:
    • Select the preset expression "None".
    • Click the button.
    • Add the different conditions via the "+" button. The regular expression is built in the "Generated regular expression" control.
    • Type the expression to check.
    • The button is used to save the regular expression. It will be proposed in the list of preset regular expressions, prefixed by "Custom".

Wizard for the MatchRegularExpression function

MatchRegularExpression allows you to use a feature wizard in the code editor. This wizard allows you to:
  • use a preset regular expression. A list of preset regular expressions is proposed.
  • view the regular expression as diagram or as sequence of conditions in a table.
  • create a regular expression. You must:
    • Select the preset expression "None".
    • Click the button.
    • Add the different conditions via the "+" button. The regular expression is built in the "Generated regular expression" control.
    • Type the expression to check.
    • The button is used to save the regular expression. It will be proposed in the list of preset regular expressions, prefixed 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
Components
WINDEVWEBDEV - Server codeReports and Queries wd230std.dll
Windows Mobile wp230std.dll
WEBDEV - Browser code WDJS.DLL
Java wd230java.jar
Linux wd230std.so
Android wd230android.jar
Minimum required version
  • Version 9
This page is also available for…
Comments
Click [Add] to post a comment