Link to home
Start Free TrialLog in
Avatar of MortenWB
MortenWBFlag for Denmark

asked on

Search among all non-blanks in string

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
Avatar of Big Monty
Big Monty
Flag of United States of America image

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.
Avatar of MortenWB

ASKER

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?
- or, btw, should I use regexp instead of instr in the if-then part??
ASKER CERTIFIED SOLUTION
Avatar of Big Monty
Big Monty
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
I think you want to do a Regex.Replace, like is done here:
https://www.experts-exchange.com/questions/28039853/Update-old-ASP-RegEx-function-for-use-in-ASP-Net.html?anchorAnswerId=38915680#a38915680

Edit: re-reading the question, I think I'm wrong about that. I'll have another think about it.
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