VBA RegExp CODE 5019

PauloCastelo

New Member
Joined
Jul 7, 2016
Messages
14
Hi folks,

It's my first time here and I'm needing your help.
I'm trying to use a specific regular expression, but when a I try execute, the message shows "Run-time error 5019"
The regular expression I'm using is "(Sumário\n[^]+)".
I done some tests and the error is "^".
How can I done it?

' Execução da Expressão regular
Dim posString As String
Dim newRegEx, newMatch, newMatches
Set newRegEx = New RegExp
newRegEx.pattern = "(Sumario\n[^]+)"


newRegEx.MultiLine = True
newRegEx.IgnoreCase = True
newRegEx.Global = True

Set newMatches = newRegEx.Execute(strTemp)

For Each newMatch In newMatches
RetStr = newMatch.Value
Next
strTemp = RetStr

My idea is take only expressions after word "Sumario".
I used a Macro to take Word Documment to insert in the string (strTemp)
When I tried used newRegEx.pattern = "(Sumario\n[]+)", it's done, but it's not works.
 
Looks like a syntax error in the expression to me. Using "^" as the first character in a bracketed expression means "not" but then you don't have any other characters in there. See here:

https://msdn.microsoft.com/en-us/library/1400241x(v=vs.84).aspx

WBD

Yes, it's a syntax error. I'd answer how can I make an expression that shows same results of ("Sumario\n[^]+").
At the regexr.com you can test yours. VBA isn't able to accept ^ in expression, so what can i do?
 
Upvote 0

Excel Facts

Remove leading & trailing spaces
Save as CSV to remove all leading and trailing spaces. It is faster than using TRIM().
[1] Provide an example of the string you're searching through.
[2] Provide an example of what you want to match / return.

I can't make this RegEx work on that site either; the [^] still doesn't make any sense.

WBD
 
Upvote 0
[1] Provide an example of the string you're searching through.

String:

Sumario
1. Descricao 5
2. Atores 5
2.1. Temporizador 5
3. Pré-Condicoes 5
4. Fluxo de Eventos 5
4.1. Fluxo Básico – Gera Arquivo SITAE 5
4.2. Fluxos Alternativos 5
4.3. Fluxos de Excecao 6
5. Requisitos Especiais 6
5.1. Periodicidade de Execucao da Rotina 6
5.2. Disponibilizacao do Arquivo 6
6. Ponto de Extensao 7
7. Pos-Condicoes 7
8. Informacoes Complementares 7
9. Referências 7
10. Regras 7
10.1. Regras de Interface 7
10.2. Regras de Apresentacao 7
11. Mensagens 7
11.1. Mensagens de Negocio 7
11.2. Mensagens de Hint 7
 
Upvote 0
[2] Provide an example of what you want to match / return.

Let's go to story :)

[1] I made a workbook to recover the content of many Word Doccuments (.doc) and search all occurrence of a specific expression.

[2] The problem is: I need to ignore everything before Sumario.

[3] So, I thought to create a RegEx to ignore everything before Sumario and consider everthing before.

[4] After this, the system would look for another RegEx in result.
 
Last edited:
Upvote 0
snb_,
I need to process with memory, if I shows in the MsgBox it not works. :(
snb was showing you the result in an example... you do not have to use a MessageBox, just assign the value to a variable or cell or wherever you want to put it. For example, if there is only one "Sumario" in the text...

SomeVariable = Split(strTemp, "Sumario")(1)

If, on the other hand, you have more than one "Sumario" in the text, then you can loop through the results of the Split function. For example...

Code:
SomeArray = Split(strTemp, "Sumario")
For X = 1 To UBound(SomeArray)
[COLOR="#008000"]  '
  '  You can process each Sumario block of text here. I am
  '  going to use a MessageBox to show you each block of text
  '  but you can take the argument to the MessageBox and
  '  assign it to something or process it directly or whatever
  '  it is you are going to do with it
  '[/COLOR]
  MsgBox SomeArray(X)
Next
 
Upvote 0
snb was showing you the result in an example... you do not have to use a MessageBox, just assign the value to a variable or cell or wherever you want to put it. For example, if there is only one "Sumario" in the text...

SomeVariable = Split(strTemp, "Sumario")(1)

If, on the other hand, you have more than one "Sumario" in the text, then you can loop through the results of the Split function. For example...

Code:
SomeArray = Split(strTemp, "Sumario")
For X = 1 To UBound(SomeArray)
[COLOR=#008000]  '
  '  You can process each Sumario block of text here. I am
  '  going to use a MessageBox to show you each block of text
  '  but you can take the argument to the MessageBox and
  '  assign it to something or process it directly or whatever
  '  it is you are going to do with it
  '[/COLOR]
  MsgBox SomeArray(X)
Next

Great Rick and snb_, I had misunderstood.

Very thanks.

I'll try it :)
 
Upvote 0
I tried too. It returns only next line.
you try to the code below

' Execução da Expressão regular
Dim posString As String
Dim newRegEx, newMatch, newMatches
Set newRegEx = New RegExp
newRegEx.pattern = "Sumario" & "(.+)"

newRegEx.MultiLine = True
newRegEx.IgnoreCase = False
newRegEx.Global = True

RetStr=newRegEx.Replace(strTemp,"$1")
strTemp = RetStr
 
Upvote 0
Try:
sumario([\w\s]*)\n
Just seen the text you are parsing, so the above may not be the solution - I will look at it again.
 
Last edited:
Upvote 0

Forum statistics

Threads
1,223,228
Messages
6,170,871
Members
452,363
Latest member
merico17

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top