Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Search among all non-blanks in string

Posted on 2014-02-25
6
Medium Priority
?
259 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 34

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
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 34

Accepted Solution

by:
Big Monty earned 1000 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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

This article discusses four methods for overlaying images in a container on a web page
Finding original email is quite difficult due to their duplicates. From this article, you will come to know why multiple duplicates of same emails appear and how to delete duplicate emails from Outlook securely and instantly while vital emails remai…
In this Micro Tutorial viewers will learn how to create navigation buttons that change on rollover, using CSS (Continuation of the CSS Image Sprite tutorial) Create a parent ID for all the list items       - Specify position: absolute and display: block…
In this tutorial viewers will learn how to style a corner ribbon overlay for an image using CSS Create a new class by typing ".Ribbon":  Define the class' "display:" as "inline-block": Define its "position:" as "relative": Define its "overflow:" as …

971 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