2

any experience with vba regex substition codes? I've tried the followings, which are working both on regex101.com and on regexr.com.

$&
\0

They are unfortunately not working in my VBA code. Any similar experience?

Example: https://regex101.com/r/5Fb0EV/1

VBA code:

    Dim MsgTxt As String
    ...

    strPattern = "(Metodo di pagamento).*\r\x07?.*"  
    With regEx
        .Global = True
        .MultiLine = True
        .IgnoreCase = True
        .Pattern = strPattern
        MsgTxt = regEx.Replace(MsgTxt, "\0#END")
    End With

Input string:

Metodo di pagamento selezionato: 
Mastercard 

Expected ouput:

Metodo di pagamento selezionato: 
Mastercard #END
4
  • stackoverflow.com/questions/22542834/… Commented Nov 24, 2019 at 15:06
  • 1
    code, input and output added Commented Nov 24, 2019 at 15:11
  • can't display here but each line has a chr(7) at the beginning Commented Nov 24, 2019 at 15:13
  • @QHarr Thanks but still not answered in linked post Commented Nov 24, 2019 at 18:00

1 Answer 1

2

Try the below code:

Sub test()

    Dim MsgTxt As String

    MsgTxt = Chr(7) & "Metodo di pagamento selezionato:" & vbCr & Chr(7) & "Mastercard "
    With New RegExp
        .Global = True
        .MultiLine = True
        .IgnoreCase = True
        .Pattern = "(Metodo di pagamento.*\r\x07?.*)"
        MsgTxt = .Replace(MsgTxt, "$1#END")
    End With
    Debug.Print MsgTxt

End Sub

Input

Metodo di pagamento selezionato:
Mastercard

Output

Metodo di pagamento selezionato:
Mastercard #END
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.