Regular Expression Examples

Separating Text And Numbers In Excel

         Regular Expressions (RegEx or Regex) are frequently used in the developer world. They are used to validate website password input, search for word patterns in texts and for many other uses.

         When using RegEx in VBA, patterns are based. In our example file, the cells of column B contain mixed (numbers, letters, etc.) data. We want to capture the numeric values from these data and list them in column C and the non-numeric values in column D.

RegEx pattern to capture numeric (numbers) values :
With RegEx
 .Global = True
 .Pattern = "\d+"
End With

RegEx pattern to capture non-numeric values :
With RegEx2
 .Global = True
 .Pattern = "[^0-9]"
End With

The captured values ​​are listed in columns C and D.





2 comments: