-1

I am having a similar issue as this question here. \s is not matching all white spaces in VBA.

But I want to catch all kinds of whitespace - spaces, tabs, newlines, thin space, hair space etc. and not only one of them.

Is there another possibility than hard coding every unicode value like the following?

With regEx
    .Global = True
    .Pattern = "(\s|\u2009|\u2008|.............)"
End With

How do I isolate a space using RegExp in VBA (\s vs. \p{Zs})? wants to isolate spaces - I want readable and reliable way to match any whitespace without needing to list the unicode values for them as proposed by the one who closed the question.

inetphantom
  • 2,498
  • 4
  • 38
  • 61
  • Depending on what you need to do with them. If you need to **remove any extra leading or trailing whitespaces**, instead of checking them through regex, why not just [`Trim()`](https://www.techonthenet.com/excel/formulas/trim.php) them instead? – Samuel Hulla Jun 27 '18 at 14:24
  • @Rawrplus - I don't think Trim works on ChrW(8203). –  Jun 27 '18 at 14:26
  • No it doesn't, though it is a place to start. Might want to trim it initially, and then remove any extra unwanted characters such as hairspace with [`REPLACE()`](https://www.techonthenet.com/excel/formulas/replace_vba.php) I am however too lazy to re-create a working replace condition / regexp for all the unwanted characters you provided above. *sorry...* – Samuel Hulla Jun 27 '18 at 14:29

1 Answers1

2

There is no perfect alternative, therefore I suggest to use exact values/codes.

You should be safe with this regex pattern:

[\s\n\r\t \xA0\u1680\u180E\u2000-\u200B\u202F\u205F\u3000\uFEFF]+
Ωmega
  • 42,614
  • 34
  • 134
  • 203