Solved

Search among all non-blanks in string

Posted on 2014-02-25
6
238 Views
Last Modified: 2014-02-25
Hi Experts,

I attempt to make a search in records containing both blank and linebreak characters. The basic InStr("str", search) only return results from the first line in the record, not recoqnizing anything under that.
Forums point out that RegExp could rid the record of unwanted blanks, so the search string applies to all non-blanks of the InStr, but so far this method eludes me. Also I need the code to ignore case.
Applied the following code and variants, but that simply fails, returning no results whatsoever, so what do I miss?


<table>
<%
Dim re, targetString, colMatch, objMatch

do while not McalRec.EOF
Set re = New RegExp
With re
  .Pattern = "\s"
  .Global = True
  .IgnoreCase = True
End With
targetString = re.Test(McalRec("notat"))

if Instr(targetString, SearchMCal) then
countallMcal = countallMcal + 1

                        response.write("<tr align='left' valign=top style='color:#FF0000;'>" &_
                        "<td style='color:#FF0000;'>" & McalRec("notat") & "</td>" &_
                        "<tr><td colspan='15'><hr></td></tr>")
else
end if
McalRec.movenext
loop
%>
</table>

Best regards
MorteWB
0
Comment
Question by:MortenWB
  • 3
  • 2
6 Comments
 
LVL 32

Expert Comment

by:Big Monty
ID: 39886853
try using
^\s*$

Open in new window

as your pattern

Explanation:

^ is the beginning of string anchor
$ is the end of string anchor
\s is the whitespace character class
* is zero-or-more repetition of
In multiline mode, ^ and $ also match the beginning and end of the line.
0
 

Author Comment

by:MortenWB
ID: 39886919
Hi Big Monty,

thank You for getting back to me:)

I put in Your pattern, but still no luck. Wonder if I understand the use of RegExp fully - are the targetString fx. placed correctly under the End With?
0
 

Author Comment

by:MortenWB
ID: 39886950
- or, btw, should I use regexp instead of instr in the if-then part??
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 32

Accepted Solution

by:
Big Monty earned 250 total points
ID: 39886958
fair warning, I am NOT a RegExp expert, I've only dabbled in them with url rewriting :)

Your targetString variable is in the write place, but doesn't look right. try changing

targetString = re.Test(McalRec("notat"))

targetString = McalRec("notat")
matchFound = re.test( targetString )

then change your if statement to

if matchFound then

here's a pretty good reference page for regexp's:

http://www.mikesdotnetting.com/Article/24/Regular-Expressions-and-VBScript
0
 
LVL 35

Expert Comment

by:Terry Woods
ID: 39887015
I think you want to do a Regex.Replace, like is done here:
http://www.experts-exchange.com/Programming/Languages/.NET/ASP.NET/Q_28039853.html#a38915680

Edit: re-reading the question, I think I'm wrong about that. I'll have another think about it.
0
 

Author Closing Comment

by:MortenWB
ID: 39887034
Ahhh - for being not an expert You are rather sharp Big Monty :) - now I get it, and it works perfectly.

Thank you very much for your help, (and thanks for joining TerryAtOpus, but Monty have saved me)

Best regards

MortenWB
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
html coding on my Tumblr blog 1 34
How can I   ajax html table  rows? 20 63
Microsoft SQL ADO Conn Issue 6 40
IP API - need data... 4 13
This is a PowerShell web interface I use to manage some task as a network administrator. Clicking an action button on the left frame will display a form in the middle frame to input some data in textboxes, process this data in PowerShell and display…
Find out what you should include to make the best professional email signature for your organization.
In this tutorial viewers will learn how to style elements, such a divs, with a "drop shadow" effect using the CSS box-shadow property Start with a normal styled element, such as a div.: In the element's style, type the box shadow property: "box-shad…
The viewer will receive an overview of the basics of CSS showing inline styles. In the head tags set up your style tags: (CODE) Reference the nav tag and set your properties.: (CODE) Set the reference for the UL element and styles for it to ensu…

895 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

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now