Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

VBScript Multi Line Pattern Match

Posted on 2009-05-07
16
Medium Priority
?
749 Views
Last Modified: 2012-06-21
I am trying to extract a SQL statement from an email. The problem is that I don't know if the email message will have a signature line or not.  

So, in the code section I would want everything before two carriage returns in a row.

The ideal match would be...

select *
from smr_retl_cnt_stg
with ur

I tried
((?:.+\r\n)*)\r\n\r
but I wasnt getting the expected results

select *
from smr_retl_cnt_stg
with ur
 
 
Chris G x83061
----------------------------
Sent from my BlackBerry Wireless Handheld

Open in new window

0
Comment
Question by:orbitus
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 8
  • 8
16 Comments
 
LVL 27

Expert Comment

by:ddrudik
ID: 24329684
In ASP/VBSCRIPT with your sample that would be:
<%
Set regEx = New RegExp
regEx.Pattern = "^[\S\s]*?(?=\r\n(?: \r\n){2}|$)"
Set Matches = regEx.Execute(yourstring)
%>

Open in new window

0
 
LVL 4

Author Comment

by:orbitus
ID: 24329797
Hi ddrudik, I am using the VB script engine in Office VBA. Identical to the Javascript engine.  Your string does not seem to work with that engine.
0
 
LVL 27

Accepted Solution

by:
ddrudik earned 2000 total points
ID: 24329824
From testing with http://regexpal.com/ the following matches your source text copied from above:
^[\S\s]*?(?=\r\n(?:\x20\r\n){2}|$)

Open in new window

0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
LVL 4

Author Comment

by:orbitus
ID: 24329896
When I go to that site and enter all the information I see a match to the entire statement. Am I not configuring the site correctly to run the test?
0
 
LVL 27

Expert Comment

by:ddrudik
ID: 24329920
Then it is likely that your source text does not match the copy-and-paste that I took from your question.  Consider copying/pasting another example here for testing.
0
 
LVL 4

Author Comment

by:orbitus
ID: 24329922
The engines must be different. This pattern works in VBA

((?:.+\r?\n)*)\r?\n\r?\n

All I had to do to fix my own was put in the optional handling of the carriage returns.

Thanks for the help though.
0
 
LVL 27

Expert Comment

by:ddrudik
ID: 24329933
If that is the case then your source differed from the sample, which had \x20\r\n in it.
0
 
LVL 4

Author Comment

by:orbitus
ID: 24329945
Using this VBA code, just posting for reference.
Dim myMatch As Match
Dim myMatches As MatchCollection
Dim myRegExp As RegExp
Set myRegExp = New RegExp
myRegExp.IgnoreCase = True
myRegExp.Pattern = "((?:.+\r?\n)*)\r?\n\r?\n"
Set myMatches = myRegExp.Execute(strSQL)
For Each myMatch In myMatches
	'matched text: myMatch.Value
	'match start: myMatch.FirstIndex
	'match length: myMatch.Length
	For I = 1 To myMatch.SubMatches.Count
		'backreference text: myMatch.SubMatches(I-1)
	Next
Next

Open in new window

0
 
LVL 4

Author Comment

by:orbitus
ID: 24329964
What is \x20, I don't see that?
0
 
LVL 4

Author Comment

by:orbitus
ID: 24329977
Here is another sample...

select *
from smr_retl_cnt_stg
with ur
 
 
Chris G x83061
----------------------------
Sent from my BlackBerry Wireless Handheld


I was looking to get just the SQL and not the signature.
0
 
LVL 27

Expert Comment

by:ddrudik
ID: 24329984
\x20 is the hexadecimal notation for the space character.
\xnn is the general syntax, here nn can be any character hex value, such as those you see in the ASCII table: http://www.asciitable.com/
0
 
LVL 27

Expert Comment

by:ddrudik
ID: 24330019
here's an example from http://regexpal.com
img.jpg
0
 
LVL 4

Author Comment

by:orbitus
ID: 24334753
Im sorry, Google Chrome and the EE site were the culprt.  The EE site keeps putting spaces on the blank lines after the SQL statement, those should not be there.  Google chrome was making regexpal not pull up any matches.

When I move over to Internet Explorer your pattern works great with the lines with spaces but not when those spaces are removed.
0
 
LVL 27

Expert Comment

by:ddrudik
ID: 24335793
Have you resolved your original question?
0
 
LVL 4

Author Comment

by:orbitus
ID: 24335820
Yes, this pattern works for me...

((?:.+\r?\n)*)\r?\n\r?\n

Your pattern obviously works with the information you pulled from the site so I'm closing  the request as you solved it.  Thanks for your help.
0
 
LVL 27

Expert Comment

by:ddrudik
ID: 24335829
Thanks for the question and the points.
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I have been reconstructing a PHP-based application that has grown into a full blown interface system over the last ten years by a developer that has now gone into business for himself building websites. I am not incredibly fond of writing PHP code o…
Do you hate spam? I do, and I am willing to bet you do as well. I often wonder, though, "if people hate spam so much, why do they still post their email addresses on the web?" I'm not talking about a plain-text posting here. I am referring to the fa…
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…

715 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question