RegEx replace do not remove spaces as expected

Here is a typical line I'm working with:

·         Identify & document site-related constraints and assumptions.

I would like to clear this line to get rid of everything before "Identify" ...

I wrote a function to take a string and clean it, here it is:

Function dataScrub(dataIn As String)
Dim dataIn_orig As String
dataIn_orig = dataIn

'BEGIN : create and set regular expression
Dim regEx
Set regEx = CreateObject("vbscript.regexp")
With regEx
        .IgnoreCase = True
        .MultiLine = False
        .Pattern = "^[\s]*[·]+[\s]*"
        .Global = True
End With

dataScrub = regEx.Replace(dataIn_orig, "")
End Function

For some unknown reason, the replacement replaces · (and not the period, rather like a bullet), but does not get rid of the spaces that follow it, so my final result is:

      Identify & document site-related constraints and assumptions.

When I test my regEx with an online tester ( http://www.regular-expressions.info/javascriptexample.html ), it works as intended.

What am I doing wrong?

+3
source share
2 answers

[\s] \, s. \s .


, , \s* , . , \b . \b ( ). :

^\s*[·]+\s*\b
+2

, , .

Cells.Replace What:=Chr(160), Replacement:="", LookAt:=xlPart
+1

Source: https://habr.com/ru/post/1726821/


All Articles