Stripping Text Between Two Strings With Regular Expressions
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
ADVERTISEMENT
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
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
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
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
My database has a field called Text that stores pre-formatted text in the form of:
String & vbcrlf
String & vbcrlf
String & vbcrlf
So there is a line of text, line break, line of text, etc and looks like:
First Line of text
Second Line of Text
Third Line of Text
. . . .
Last Line of Text
I've created a regular expression that searches for instances of line feeds followed by any character ....
View Replies
View Related
I want to strip email from the text. Some of my users may send me a string:
str = "This is email 1: Join Bytes! and here is email 2: <a
href="mailto:me@me.com">me@me.com</a>"
How do I parse the string to get email address only? mI know I may use instr() to determine if email address exists, but please, give me a hint on how to handle it next.
View Replies
View Related
how do I strip this to obtain certain text:
varaible to strip:
connString="driver={SQL
Server};server=SERVER_NAME;uid=USER_ID;pwd=PASSWOR D;database=DB_NAME"
text required:
Server_name, User_Id, Password, DB_Name
View Replies
View Related
I have text in a field coming from a database. The text has various
forms such as:
text1
text1 or text2
text1 or text2 or text3
text1; or text2
text1; or text2; or text3
etc...
how can I parse this with a reg ex? I tried this:
(.+);? or
but it only captures 1 submatch (text1) and only if theres an "or"
after it
I'd like to get 1 submatch for each piece of text separated by the
"or", just the text itself if there is no or.
Anyone know how to do it?
View Replies
View Related
How do I take a string value and trim off the last character?
View Replies
View Related
In Javascript, there is a feature where you can alter text strings by just using part of a string, just taking the third letter, fourth letter, etc.
Is there a feature like this using ASP (VBScript)? Or if not using ASP, what about ASP.NET?
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
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
i have a record that is returned by the database as domain/username. i want to be able to strip off "domain/" and just display "username". is this possible? if so, how would i go about doing this?
View Replies
View Related
My ASP page allows user to enter comments into a form. To avoid
errors I'm having to strip out double quotes before saving to the
database. Is there anyway to encode these so that I can store them
instead, in the way was an URLEncode works?
View Replies
View Related
I'm trying to replace all the " in my variable with ', but I can't seem to get it right.
editizecontent = Replace(Request("EDITIZE"), """, "'")
Would this work?
View Replies
View Related
in my front end uses will type in a date in a text box. in the code it want to call each individual i.e the month the day and the year i am not sure of how to do this.
View Replies
View Related
i have a record that is returned by the database as domain/username. i want to be able to strip off "domain/" and just display "username". is this possible? if so, how would i go about doing this?
View Replies
View Related
a small code snippet that will strip the /n from a string?
View Replies
View Related
I know there is a way of stripping out special characters from a string however I need a way of stripping out "" marks from a string or what i really want is to replace all double ("") marks in a string with single ('') marks before inserting the string into a database. Is there a way of doing this in ASP?
View Replies
View Related
I'm querying a text field with an 8000 character limit. The text also
contains HTML tags like <p> <br> and more. Is there a way to strip all HTML
tags in the resulting recordset, or do I have to replace each tag
individually?
View Replies
View Related
I'm trying to strip out none alphanumeric characters (and a couple of punctuation marks) from a string before inserting into a database.
I've put in my code below, basically I thought I'd loop through each character in turn and pass it through a regular expression to check its validity. If it passes I'll add it to a global variable ('validString') if it fails I'll remove it.
But I can't get my Mid() function to accept 'i' as a value so it won't loop. Code:
View Replies
View Related
I have an asp page that reads the contents of a database and creates an xml news feed. I have code that strips out the <BR> and <P></P> tags, but it looks one of the databases I'm trying to read from uses only <P> without the closing tag.
So the make a long story short, I can't figure out what to add to my code to strip out these tags (or if that isn't the problem at all!) Code:
View Replies
View Related
I'm trying to catch some characters in a string before they are entered into a database that are not ASCII and convert them to ASCII characters. The characters in question are the angular double quotes but this could be associated with similar occurences. I want to check for left angular double quotes [“] or right angular double quotes [“] and replace them with straight double quotes ["].
(I'm not actually storing the HTML equivalents - they are simply there to give you an idea of which characters I'm on about.)a way of catching these buggers? I've tried using chr(8220) (the numeric code for one of the illegal characters apparently) but ASP has a problem working with numbers outside the character map.
View Replies
View Related
I need to make a function that takes Request.QueryString elements and strips all single quotes from the input.
function StripQuotes(array)
dim StripQuotes
for each old in array
new = replace quotes (old)
Add new to StripQuotes
next
return StripQuotes
end function
View Replies
View Related
Does anyone know of a function that will take the file pathname and just keep the file name before doing an insert into a database? Code:
View Replies
View Related