Regular Expressions & Replace Method
Problem: I want to check the data from a RecordSet.GetString result for today's date. If today's date exists in the row then I want to replace the preceeding <tr> tag with a <tr style='background:grey'>. I made the following objRegExp.Pattern:
.Pattern= "<tr><td><font size='1'>[w]*</font></td><td><font size='1'>[w]*</font></td><td><font size='1'>" & FormatDateTime(now(),vbShortDate)
This successfully identifies the row as containing today's date. Yea! Now, the replace part.
text = objRegExp.Replace(text,"<tr style='background:grey'><td><font size='1'></font></td><td><font size='1'></font></td><td><font size='1'>" & FormatDateTime(now(),vbShortDate))
This piece works except I lose the data that was actually contained in each cell. How can I have it so that the only thing that gets replaced is the table row tag?
View Replies
ADVERTISEMENT
Been pounding on this for an hour and eating up my day's productivity, so I thought I'd throw a question out there. (I'm also reading through the Google archives to try to find this answer...)
Windows 2000 Small Business Server
Using regular expressions for the first time, and having difficulty with the replace method. We're searching through a list of vehicle models, trying to replace what we get from the client data with correctly propercased text...ie..we get FORD F150 and replace it with Ford F150; CHEVROLET ES 300 and replace it with Chrevrolet ES 300; ACURA MDX >> Acura MDX. The usual propercase algorithms don't work because of the multiple capitals in some of the model names: we don't want Acura Mdx.
The test method always works. The problem we're having is that, under certain circumstances, the replace method is replacing too much. We've created a table of capitals as they relate to models: ES; MDX; XL; SL; and so on. The pattern we're using is this: ....
View Replies
View Related
I want to get the Structure within the 2 HTML Tags. I am not able to Get the regular expression for it. So here is the Code and could anyone give m ethe regular expression to get the HTML tags between the Code:
View Replies
View Related
how to use Regular Expressions in ASP .
View Replies
View Related
Im trying to replace all occurences of a newline with a <br /> tag using regular expressions.
However, I only want to replace the newline with a <br /> tag if the newline does NOT come directly after an </h2> tag.
I cant seem to work out a regular expression to do this. So, for example.
This is an example line. You can see how it would work. would create
This is an example line.<br /><br />You can see how it would work.
and
<h2>The Heading</h2>
This is an example line.
You can see how it would work.
would create
<h2>The Heading</h2>This is an example line.<br /><br />You can see how it would work.
View Replies
View Related
I have been trying to run the example listed on MSDN to test a regular
expression. I'm running a win2k3 web server edition, WSH is version5.6.
I am getting an error everytime I run
Set RegEx = New RegExp
I have seen a few problems on MSDN with users not getting the right
permissions for some dll's so I went through the procedures trying to
correct that. I've seen the RegExp values in the registry. Even had a
friend of mine try the script on his machine. (mind you this comes
directly from MS) I cannot get New RegExp to work at all
View Replies
View Related
I've got a page of text which I am assigning to a string. Within this
page there are special tags e.g. lots of text....<ti>dogs</ti>..lots
more text....<ti>this is a cat</ti> etc.. So I've got a long string
interspersed with these tags. Now what I need to do is get a list of
the words/phrases that are within these tags. So in my list I would
get dogs, this is a cat etc..
I've tried a combination of mid, instr and replace and got it sort of
working but there's got to be a more efficient way of doing it.
Possibly using regular expressions?
View Replies
View Related
Can I use regexps in fso.DeleteFile? I've found I can use a '?' and probably a '*' (although that seems a tad brutal) but I'm having trouble with expressions like ([a-z]|[0-9]-).
Am I wasting my time trying to get it to work (i.e. does it support them?) If so, how do I use them? Does it have its own quirky syntax or "standard" regexp? Every example I've found so far just mentions deleting something simple like *.txt.
For the record, I need to "tidy up" a directory full of images by deleting files whose names _don't_ contain particular text. It's quite convoluted and would be far easier if I could just go through each file one by one but hey. Here are the details:
1) I have a list of IDs in an array that I've read from a data source. This is the "current ID" list
2) I have a list of image filenames from a directory in another array. The image filenames contain an ID in them. There could be none, one or more images containing the same ID.
3) I look at each file in turn, extract the ID portion and add it to an array of "found" IDs - crucially, this array is only updated if the ID has not been seen before in another filename
4) I then step through this array and use Filter() to see if the ID is in the "current ID" list somewhere
5) If it is missing from the list, that ID is deemed "out of date" and all associated images containing that ID need to be deleted. Message to screen saying that ID has been deleted.
6) If it is in the list, just print a message saying it is "current" and move on.
I realise I could just step through each file and test it against the current ID list but then the output on-screen would be file-by-file and not ID-by-ID. The client doesn't care how many files there are; they don't even care about the underlying structure - they just point the browser to my script and it deletes the files, shows them which IDs have been removed and tells them how many IDs in total have been deleted.
If I went down that route I would have to keep a record of which IDs I've deleted and output the lot at the end instead of 1 by 1 as I go, which leaves the browser hanging for a while and doesn't give the client reassuring feedback as it ploughs through the directory adding the results to the screen row by row. Code:
View Replies
View Related
I am working on an ASP page that parses text using the VBScript.RegExp
regular expression object. My reg expression right now is as follows:
[a-z]+.[a-z]+.[a-z]+/
And if find URL's no problem like: windowsupdate.microsoft.com,
www.cnn.com, etc.
But I need to also find any URL, like these:
www.amazon.com/books/atoz/index.html
OR
msdn.microsoft.com/newsgroups/default.aspx
Some URL with a deeper path than something.something.com if that makes
sense. Any ideas?
View Replies
View Related
What regular expression would I use to take out all of the money (US amounts) from a string?
Right now I have:
Code:
Set RegularExpressionObject = New RegExp
With RegularExpressionObject
.Pattern = "$(.*)"
.IgnoreCase = True
.Global = True
End With
xmlText = RegularExpressionObject.Replace(xmlText,"")
Set RegularExpressionObject = Nothing
which obeously doesn't work. What should I use for:
.Pattern = "$(.*)"
??
View Replies
View Related
I have created a template system, and someone pointed a script out that would let me create simple links by using [link]home|http://www.sitepoint.com[/link] which would convert anything between those custom tags into a link, with home being the text displayed and the web address the location.
Now I need a way to be able to edit the script, well the RE Pattern so I can use it for other things. Code:
View Replies
View Related
I have a problem. Of course, or I wouldn't be posting here. Ok, now that Mr. Obvious is out of the way ...
I'm looking for some ideas. Take a look at the code below. I'm looking for the most efficient way to validate form field input on the server-side. I'll provide what I have. What I'm looking for are improvements.
<%
Function Validate_Input(Expression,Pattern)
Dim objRegExp
if Expression <> "" and Pattern <> "" then
Set objRegExp = New RegExp
select case (Pattern)
case "US_PHONE"
' sample matches: 1-(123)-123-1234 / 123 123 1234 / 1-800-ALPHNUM
' sample non-matches: 1.123.123.1234 / (123)-1234-123 / 123-1234
objRegExp.Pattern= "^([0-9]( |-)?)?((?[0-9]{3})?|[0-9]{3})( |-)?([0-9]{3}( |-)?[0-9]{4}|[a-zA-Z0-9]{7})$"
case "US_DATE"
' sample matches: 02/29/2084 / 01/31/2000 / 11/30/2000
' sample non-matches: 02/29/2083 / 11/31/2000 / 01/32/2000
objRegExp.Pattern= "(((0[13578]|10|12)([-./])(0[1-9]|[12][0-9]|3[01])([-./])(d{4}))|((0[469]|11)([-./])([0][1-9]|[12][0-9]|30)([-./])(d{4}))|((2)([-./])(0[1-9]|1[0-9]|2[0-8])([-./])(d{4}))|((2)(.|-|/)(29)([-./])([02468][048]00))|((2)([-./])(29)([-./])([13579][26]00))|((2)([-./])(29)([-./])([0-9][0-9][0][48]))|((2)([-./])(29)([-./])([0-9][0-9][2468][048]))|((2)([-./])(29)([-./])([0-9][0-9][13579][26])))"
case "EMAIL_ADDRESS"
' sample matches: asmith@mactec.com / foo12@foo.edu / bob.smith@foo.tv
' sample non-matches: joe / @foo.com / a@a
objRegExp.Pattern= "^([a-zA-Z0-9_-.47]+)@(([[0-9]{1,3}.[0-9]{1,3}.[0-9]{1,3}.)|(([a-zA-Z0-9-]+.)+))([a-zA-Z]{2,7}|[0-9]{1,3})(]?)$"
'The next line is supposed to be an RFC 2822 address compliant validation expression
'objRegExp.Pattern= "^(?:[w!#$\%&'*+-/=?^`{|}~]+.)*[w!#$\%&'*+-/=?^`{|}~]+@(?:(?:(?:[a-zA-Z0-9](?:[a-zA-Z0-9-](?!.)){0,61}[a-zA-Z0-9]?.)+[a-zA-Z0-9](?:[a-zA-Z0-9-](?!$)){0,61}[a-zA-Z0-9]?)|(?:[(?:(?:[01]?d{1,2}|2[0-4]d|25[0-5]).){3}(?:[01]?d{1,2}|2[0-4]d|25[0-5])]))$
case "ZIP"
' sample matches: 78754 / 78754-1234 / G3H 6A3
' sample non-matches: 78754-12aA / 7875A / g3h6a3
objRegExp.Pattern= "^(d{5}-d{4}|d{5})$|^([a-zA-Z]d[a-zA-Z] d[a-zA-Z]d)$"
case "CREDIT_CARD"
' sample matches: 6011-1111-1111-1111 / 5423-1111-1111-1111 / 341111111111111
' sample non-matches: 4111-111-111-111 / 3411-1111-1111-111 / Visa
objRegExp.Pattern= "^((4d{3})|(5[1-5]d{2})|(6011))-?d{4}-?d{4}-?d{4}|3[4,7]d{13}$"
case "NAME"
' sample matches: T.F. Johnson / John O'Neil / Mary-Kate Johnson
' sample non-matches: sam_johnson / Joe--Bob Jones / dfjsd0rd
objRegExp.Pattern= "^[a-zA-Z]+(([',.- ][a-zA-Z ])?[a-zA-Z]*)*$"
case "ADDRESS"
' sample matches: 2222 Mock St. / 1 A St. / 555-1212
' sample non-matches: [A Street] / (3 A St.) / {34 C Ave.}
objRegExp.Pattern= "^[a-zA-Z0-9s.-]+$"
case "CURRENCY"
' sample matches: $3,023,123.34 / 9,876,453 / 123456.78
' sample non-matches: 4,33,234.34 / $1.234 / abc
objRegExp.Pattern= "^$?([0-9]{1,3},([0-9]{3},)*[0-9]{3}|[0-9]+)(.[0-9][0-9])?$"
case else
Response.Write("Invalid syntax used to call form validation function.")
Response.End
end select
Validate_Input = objRegExp.Test(Expression)
else
Response.Write("Invalid syntax used to call form validation function.")
Response.End
end if
End Function
' Get data from the form collection and assign to variables
dim str_Customer_Email
dim str_Customer_Phone
dim str_Customer_Name
dim str_Customer_Zip
str_Customer_Email= Request.Form("email")
str_Customer_Phone= Request.Form("phone")
str_Customer_Name= Request.Form("name")
str_Customer_Zip= Request.Form("zip")
if not (Validate_Input(str_Customer_Email,"EMAIL_ADDRESS")) then response.write ("error")
if not (Validate_Input(str_Customer_Phone,"US_PHONE")) then response.write ("error")
if not (Validate_Input(str_Customer_Name,"NAME")) then response.write ("error")
if not (Validate_Input(str_Customer_Zip,"ZIP")) then response.write ("error")
response.end
%>
Now, I'll obviously want to do more than write "error" to the screen with the validated input. What I *really* want ideas on is a more efficient way to validate the fields. In this small example doing them as one-offs isn't bad. On a form that has 20-30 fields it becomes cumbersome.
View Replies
View Related
I need to strip some text from between two strings, my code looks like this:
SECTION = "My page name"
I need to build a regular expression that will return:
My page name Anyone know how to do this?
View Replies
View Related
addContent = replace(addContent,"<font>","")
Right, pretty simple eh!
However, what I need is something to say replace all occurence of strings that start with "<font" to eb replaced by zilch i.e.
<font>
<font color=green>
<font tag=this another=more>
I believe regular expression are the way to go?
View Replies
View Related
I am new to reg expressions and would like to write a regex for a .html page I am working. I want the regex to find every http link (<a href= ) that contains .org. Once it finds every link that contains .org I want to then remove ( exit.asp?url= ) that precedes it as well as add the attribute ( target="_blank" ) to the (<a href=) tag.
This basically will find all instances where I am calling my .asp page that lets the user know they are exiting the main site for an outside source and eliminate this page as long as the link they are clicking is within the original site. Otherwise I call my exit.asp page which notifies the user they are leaving.
Example:
Look for this type of tag (one where the link contains .org):
<a href="exit.asp?url=http://myorgwebsite.org/myorg"> Link 1</a>
Replace with this (removes the "exit.asp?url=", but adds target="_blank" attribute):
<a href="http://myorgwebsite.org/myorg" target="_blank"> Link 1</a>
View Replies
View Related
I need an asp command to strip out from a string all extra punctuation such as apostrophe, comma, period, spaces dashes, etc etc and just leave the letters.
View Replies
View Related
I can see how this works, but can anyone clarify what purpose the 1, 1 serves?
Code:
strSearchKeywords = replace(strSearchKeywords, ",", "", 1, 1)
View Replies
View Related
I'm trying to add a search facility to a page that looks for matches in one,
other or both memo fields of a database. The code below works fine if the
visitor types in one word, or the term just happens to exist in one of the
queried fields.
What I'd really like is for a visitor to type in an expression, or query in
the same format as you would use in a search engine and it would find
appropriate matches. Any ideas how I can modify the code below to do this?
View Replies
View Related
If I replace "a" with "b", and then I replace "b" with "a", shouldn't I get the same result? That is what I am trying to encode and decode with Replace() function, but it is giving me different things when I replace and replace again. Here is what I am talking about: Code:
View Replies
View Related
Getting this error:
The name 'squibble' is not permitted in this context. Only constants, expressions, or variables allowed here. Column names are not permitted.
/squibble/incFunc.asp, line 13
when trying the following:
Code: ....
View Replies
View Related
Can anyone give me a regular expression for finding a URL in a string of
text?
Essentially what I want to do is find URLs in a text string and embed
them in {a href...} tags. However, I haven't used regular expressions
all that much in ASP/VBSCRIPT.
View Replies
View Related
I need to create a regular expression for a date field that works only
in the following format MM/DD/YYYY with the / in the format. No other
format can be inputted into the field. I need 2 numbers for MM 2
Numbers for DD and 4 numbers for YYYY. If the users enter 1 number for
month, 1 for day he should get an alert.
I have this code and thought it was working but it is not.
var RegExPattern = /(d{1,2})W(d{1,2})W(d{4})/;
View Replies
View Related
I have a reg exp pattern as below works fine for the string : <param name="url" value="contents/cf_intro.htm" valuetype="ref">
mObjRegExp.pattern="<param.+?value=""([^""]+)""
But the same is not working for
<param name="url" valuetype="ref" value="../fmmain/fmindex.htm"
note that, i want to capture the url that comes after value=". if the value=" comes in the second place in the html tag it works. but if it comes in the 3rd position, then it doesn't work.
View Replies
View Related
i know there are tutorials for Regular Expressions too, but can a 'simple' example be posted in these forms
View Replies
View Related
I'm going down the road of learing the pattern matching in regular
expressions, and I'm trying to convert the characters into English in my
head so I can see whats happening...
For clarity with this one...
[b]([^]]+)[/b]
Ok - the first thing I did was break it up - because it looks a nightmare
like that...so now I have..3 parts..
[b]
([^]]+)
[/b]
In part 1 I under stand that the is telling the expression that a special
character is coming next, thus escaping the [ and ] respectively, thus ,
and in part 3 I understand the same and also the escaping of the /, thus
- no problems so far...
In part 2 I'm assuming that the brackets are seperating a "pattern" so that
I might reference it as $1 later on, I understand that the [^] are saying
"not enclosed" so therefore it's going to ignore a ], the + sign however
perplexes me - my VBScript book says "Matches the preceeding character one
or more times" - so does that mean the ] just before it, or does it mean the
character OR characters defined within the [ ] etc?
View Replies
View Related
looking for a regular expression example for asp in vbscript. just want to search for a name in some text, possibly display that text.
View Replies
View Related
I'm trying to find a regular expression function to strip contents out of a string which lie between square brackets [].I've got one for chevrons (to remove HTML - as below), but would prefer not to have to replace the chevrons for square brackets first.Code:
function funRemoveHTML( strText )
Dim RegEx
Set RegEx = New RegExp
RegEx.Pattern = "<[^>]*>"
RegEx.Global = True
funRemoveHTML = RegEx.Replace(strText, "")
end function
how I can modify this for square brackets as opposed to chevrons?
View Replies
View Related
I am working on an ASP page which looks in a set of text for web page URLs.
Using the VBScript.RegExp regular expression object, I have this regular
expression:
[a-z]+.[a-z]+.[a-z]+/
And it works well finding URL's such as: windowsupdate.microsoft.com,
www.cnn.com, etc.
However, I have been trying to modify it to ALSO find URL's like this:
www.amazon.com/index/sell/ie6.html?val=1
Or
www.microsoft.com/windowsxp
Any ideas?
View Replies
View Related
I'm making url's out of text starting with "www" etc. but I've got two problems. Firstly, if the string begins with www it doesn't get matched, and secondly, if there's a dot or a comma directly after the url, it becomes part of the url. I hope someone who is better at this than me will be able to help me out. Code:
reg.Pattern = "(s)(www)(S)(S+)"
s = reg.Replace(s, "$1<a href=""http://$2$3$4"" target=""_blank"">$2$3$4</a>")
View Replies
View Related
I have been using a regular expression that I don’t uite understand to
filter the valid email address. My regular expression is as follows:
<asp:RegularExpressionValidator id="valValidEmail"
runat="server"
ControlToValidate="txtEmail"
ValidationExpression="^([_a-z0-9-]+)(.[_a-z0-9-]+)*@([a-z0-9-]+)(.[a-z0-9-]+)*(.[a-z]{2,4})$"
ErrorMessage="Invalid Email address."
Display="None">
</asp:RegularExpressionValidator>
Can someone explain me why the email address Join Bytes! is
considered an invalid email address?
Also can someone explain me what the above regular expression means?
View Replies
View Related
I need to parse the following:
aaa_bbb_d_yyyy_mm.ext
aaa = ITM, CPF, FAC, GEN
bbb = almost anything (even more then 3 chars)
d = M,Q,Y,R
yyyy = year
mm = month
I'm terrible at figuring out regexp so I turn to the kind folk of SP
View Replies
View Related
I have a field that should take a date in the following two formats:
MM/DD/YYYY or MM/DD (and assume it is this year, it will fill in current year)
I have my program checking against two regular expressions. The first one is ok:
Dim regEx
Set regEx = New RegEx
regEx.Pattern = "^(([1-9])|10|11|12)/(([1-9])|((1|2)[0-9])|30|31)/200[0-9]"
If the date checked comes up False, it then goes to this expression:
regEx.Pattern = "^((0[1-9])|(10|11|12))/((0[1-9])|((1|2)[0-9])|30|31)"
My problem is on the second one. If I enter an erroneous date like this: 11/189
It will go through and crash my program.
View Replies
View Related
I am using regular expression to replace the text, This is asp function I have used to replace the text, but it’s not working properly Code:
View Replies
View Related