MortenWB
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
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
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?
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?
ASKER
- or, btw, should I use regexp instead of instr in the if-then part??
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
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.
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.
ASKER
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
Thank you very much for your help, (and thanks for joining TerryAtOpus, but Monty have saved me)
Best regards
MortenWB
Open in new window
as your patternExplanation:
^ 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.