Solved

Search among all non-blanks in string

Posted on 2014-02-25
6
236 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
Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

 
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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Do you want to insert HTML5 video into your site? This is the tutorial how to do so. What are the main advantages of HTML5 video? 1) Have good compression, good image quality, and low decode processor use. 2) It is royalty-free 3) It is easi…
This article explains how to prepare an HTML email signature template file containing dynamic placeholders for users' Azure AD data. Furthermore, it explains how to use this file to remotely set up a department-wide email signature policy in Office …
In this tutorial viewers will learn how add a scalable full-width header using CSS3. Create a new HTML document with an internal stylesheet. Set a tiled background.:  Create a new div and name it Header. Position it with position:absolute at the top…
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

706 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

18 Experts available now in Live!

Get 1:1 Help Now