Solved

Search among all non-blanks in string

Posted on 2014-02-25
6
240 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 33

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
Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

 
LVL 33

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

Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Javascript to allow login/password authorization 4 44
Wrapper for APPs 9 76
send keys not working in vba 7 58
How to get this page layout correct 13 28
Have you tried to learn about Unicode, UTF-8, and multibyte text encoding and all the articles are just too "academic" or too technical? This article aims to make the whole topic easy for just about anyone to understand.
Find out what you should include to make the best professional email signature for your organization.
In this tutorial viewers will learn how to embed videos in a webpage using HTML5. Ensure your DOCTYPE declaration is set to HTML5: "<!DOCTYPE html>": Use the <video> tag to insert a video. Define the src as the URL of your video; this is similar to …
The viewer will learn the basics of jQuery, including how to invoke it on a web page. 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.: (CODE)

813 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

14 Experts available now in Live!

Get 1:1 Help Now