Regular Expressions in VBA - Extract substring

3

In the text below, I would like a regular expression pattern, compatible with VBA, to extract the text located between the equal sign "=" and the first line break (highlighted in bold): Home Customer = WITH ABCD CLIENT

R $ 0 - (0.00%) - Max. R $ 0 - (0.00%) Base Amount - R $ 0.00 Amount Determined Financial - R $ 0, 00 - (0.00%)

    
asked by anonymous 28.09.2017 / 21:21

1 answer

0
  

[...] I would like a regular expression pattern, compatible with VBA,   to extract the localized text between the equal sign "=" and the    first line break [...]

There are 2 ways to capture this:

  • You can use this regex:

    ^.*?= *(.*)

  • Or use this regex without global flag / g (check if this enabled, is usually enabled by default ).

    = *(.*)

Both will return everything after = by ignoring the spaces between it and the first character.
You can see the operation of the 1st example here
You can see the operation of the 2nd example here

  

Why not simply use the "Client=" sequence before?

Using this sequence would certainly give the same result, but only in this example. As the objective of the user who asked is " capture between the equal sign"=" and the first line break [...]" something can not be done based in the sequence of characters in the first line of the example
I believe that the right thing is to use tokens which represent these conditions as delimiters for the capture, so the regex will display the desired results regardless of changes in sequence before the first = .

    
29.09.2017 / 16:28