Click here to Skip to main content
15,911,785 members
Home / Discussions / Regular Expressions
   

Regular Expressions

 
QuestionRe: Regex code to check textfield is working until a 'enter' is given Pin
User 1013254615-Mar-18 6:42
User 1013254615-Mar-18 6:42 
AnswerRe: Regex code to check textfield is working until a 'enter' is given Pin
Member 1255403315-Mar-18 6:53
Member 1255403315-Mar-18 6:53 
GeneralRe: Regex code to check textfield is working until a 'enter' is given Pin
User 1013254616-Mar-18 3:07
User 1013254616-Mar-18 3:07 
GeneralRe: Regex code to check textfield is working until a 'enter' is given Pin
Member 1255403316-Mar-18 4:51
Member 1255403316-Mar-18 4:51 
Questionregular expression to find tax file numbers Pin
Copalol3-Dec-17 19:08
Copalol3-Dec-17 19:08 
AnswerRe: regular expression to find tax file numbers Pin
Peter_in_27803-Dec-17 19:48
professionalPeter_in_27803-Dec-17 19:48 
GeneralRe: regular expression to find tax file numbers Pin
jschell5-Dec-17 12:06
jschell5-Dec-17 12:06 
AnswerRe: regular expression to find tax file numbers Pin
George Jonsson4-Dec-17 23:25
professionalGeorge Jonsson4-Dec-17 23:25 
GeneralRe: regular expression to find tax file numbers Pin
Copalol5-Dec-17 13:05
Copalol5-Dec-17 13:05 
GeneralRe: regular expression to find tax file numbers Pin
jschell8-Dec-17 6:51
jschell8-Dec-17 6:51 
AnswerRe: regular expression to find tax file numbers Pin
jschell5-Dec-17 12:22
jschell5-Dec-17 12:22 
GeneralRe: regular expression to find tax file numbers Pin
Copalol5-Dec-17 13:32
Copalol5-Dec-17 13:32 
QuestionCorrect Expression For 'Any Character Including Whitespace' Pin
Sonhospa7-May-17 9:23
Sonhospa7-May-17 9:23 
SuggestionRe: Correct Expression For 'Any Character Including Whitespace' Pin
Richard MacCutchan7-May-17 21:22
mveRichard MacCutchan7-May-17 21:22 
GeneralRe: Correct Expression For 'Any Character Including Whitespace' Pin
Sonhospa7-May-17 23:12
Sonhospa7-May-17 23:12 
GeneralRe: Correct Expression For 'Any Character Including Whitespace' Pin
Richard MacCutchan7-May-17 23:30
mveRichard MacCutchan7-May-17 23:30 
AnswerRe: Correct Expression For 'Any Character Including Whitespace' Pin
Bernhard Hiller7-May-17 23:13
Bernhard Hiller7-May-17 23:13 
AnswerRe: Correct Expression For 'Any Character Including Whitespace' Pin
Sonhospa8-May-17 0:24
Sonhospa8-May-17 0:24 
GeneralRe: Correct Expression For 'Any Character Including Whitespace' Pin
Richard MacCutchan8-May-17 2:25
mveRichard MacCutchan8-May-17 2:25 
QuestionHow to retain characters preceding a match? Pin
Member 1297660431-Jan-17 15:44
Member 1297660431-Jan-17 15:44 
AnswerRe: How to retain characters preceding a match? Pin
Peter_in_278031-Jan-17 19:27
professionalPeter_in_278031-Jan-17 19:27 
GeneralRe: How to retain characters preceding a match? Pin
Member 1297660431-Jan-17 20:50
Member 1297660431-Jan-17 20:50 
QuestionUsing back references to find data type naming standards violations Pin
Member 124482999-Apr-16 7:06
Member 124482999-Apr-16 7:06 
AnswerRe: Using back references to find data type naming standards violations Pin
George Jonsson16-Apr-16 18:36
professionalGeorge Jonsson16-Apr-16 18:36 
There is most likely a more elegant way to do this, but this expression should work.

[EDIT] It is the second group that should be back-referenced, hence \2
Dim\s+(?<variable_name>\w_\w_\w+_(?<expected_type>\w+)_\w+)\s+As\s+(?:(?<matched_type>\2)|(?<mismatched_type>\w+))


The line
VB.NET
Dim L_V_Scalar_Integer_Item As Integer

will give the result
expected_type   matched_type   mismatched_type
Integer         Integer


The line
VB.NET
Dim L_V_Scalar_Integer_Item As String

will give the result
expected_type   matched_type   mismatched_type
Integer                        String


Example in c#
C#
Match m = Regex.Match("Dim L_V_Scalar_Integer_Item As String", 
"Dim\s+(?<variable_name>\w_\w_\w+_(?<expected_type>\w+)_\w+)\s+As\s+(?:(?<matched_type>\2)|(?<mismatched_type>\w+))");
if (m.Success)
{
    // For example, check if the group named 'matched_type' is empty
    // This means that there is a violation of the naming convention
    if (String.IsNullOrEmpty(m.Groups["matched_type"].Value))
    {
        string errorText = String.Format(@"The type '{0}' is not allowed for variable name '{1}'. 
        The correct type is '{2}'", 
        m.Groups["mismatched_type"].Value,
        m.Groups["variable_name"].Value,
        m.Groups["expected_type"].Value);
    }
}
else
{
    // Do some error handling for a failed match
}


modified 18-Apr-16 1:30am.

GeneralRe: Using back references to find data type naming standards violations Pin
Member 1244829917-Apr-16 17:20
Member 1244829917-Apr-16 17:20 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.