PC SOFT

WINDEVWEBDEV AND WINDEV MOBILE
ONLINE HELP

Home | Sign in | English UK
  • 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.
WEBDEV - Browser code MatchRegularExpression is using the syntax of regular expressions available in Javascript.
Example
WEBDEV - Server codePHPAjax
// 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
WEBDEV - Server codePHPAjax
// 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
WEBDEV - Server codePHPAjax
// 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(<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 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, 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
WEBDEV - Server codeAjax

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
WEBDEV - Server codeAjax

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.
WEBDEV - Server codeAjax

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
WEBDEV - Server codeWEBDEV - Browser codePHPAjax

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
WEBDEV - Server codeWEBDEV - Browser codePHPAjax

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")
WEBDEV - Server codeWEBDEV - Browser codePHPAjax

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
WEBDEV - Server code
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. Simply:
    • Select the preset expression "None".
    • Click .
    • 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. Simply:
    • Select the preset expression "None".
    • Click .
    • 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. Simply:
    • Select the preset expression "None".
    • Click .
    • 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
Component : wd250std.dll
Minimum version required
  • Version 9
This page is also available for…
Comments
OBSERVAÇÃO
Use field event: Whenever modifying / Whenever modifying
Thus each character entered is validated the field.

Use o evento do campo: Whenever modifying / Sempre que modificar
Assim a cada caracter digitado é feita a validação do campo.

Utiliser événement de champ: chaque fois que vous modifiez / chaque fois que vous modifiez. Ainsi chaque caractère saisi est validé dans le champ.

EDT_VALOR_MAXIMO_RESPOSTA..InputMask = "regexp:[0-9]{0,9}[.]{0,1}[0-9]{0,9}"
EDT_VALOR_MAXIMO_RESPOSTA..CursorEnd = Length (EDT_VALOR_MAXIMO_RESPOSTA) + 1
EDT_VALOR_MAXIMO_RESPOSTA..Cursor = EDT_VALOR_MAXIMO_RESPOSTA..CursorEnd


LINK EXAMPLE

https://forum.pcsoft.fr/fr-FR/pcsoft.br.windev/1985-expressao-regular-mascaras-validacao-campo-picture/read.awp
BOLLER
06 Dec. 2019
Exemplo de campo texto que só recebe números e ponto
Edt_Campo..InputMask = "regexp:[0-9]{0,9}[.]{0,1}[0-9]{0,9}"

O campo vai receber valores iguais a 0123456789.0123456789
10 números inteiros até 10 casas decimais usando ponto como valor decimal

Edt_Campo..InputMask = "regexp:[0-9]{0,9}[.]{0,1}[0-9]{0,2}"

O campo vai receber valores iguais a 0123456789.01
10 números inteiros até 2 casas decimais usando ponto como valor decimal

IMPORTANTE: Use o evento "Whenever modifying" / "Sempre que modificar", assim cada caracter que for digitado imediatamente valida o campo.

Edt_Campo..InputMask = "regexp:[0-5]{0,5}[.]{0,1}[0-9]{0,2}"

O campo vai receber valores iguais a 012345.01
6 números inteiros com até 2 casas decimais usando ponto como valor decimal
BOLLER
05 Dec. 2019
Video MatchRegularExpression
https://youtu.be/_Q_DoUepmRM

https://windevdesenvolvimento.blogspot.com/2019/05/dicas-2117-windev-webdev-mobile-email-8.html

// btn_email_confere_MatchRegularExpression

IF MatchRegularExpression(EDT_EMAIL, "[-.a-z0-9]+[@][-.a-z0-9]+[.][a-z]{2,4}") = True THEN
Info("O Email : " + EDT_EMAIL + " está correto")
ELSE
Info("Email invalido")
END

amarildo
21 May 2019