|
-
Oct 9th, 2008, 09:02 PM
#1
Thread Starter
Fanatic Member
[RESOLVED] Regular expression to find Tokens in HTML page
Hey there,
im trying to create a regular expression to replace Tokens on an HTML page.
each token will begin with |~ and end with ~|
eg1: |~TOKEN1~|
eg2: |~MY TOKEN~|
eg2: |~Another_Token~|
these can lie anywhere in HTML page, so all i care about is whats between the start and end delimiters
im struggling with creating a pattern.
what i have tried is "|~[A-Za-z0-9_]~| but it doesnt work for me..
any help is appreciated
Barry
Visual Studio .NET 2008/Visual Studio .NET 2005/Visual Studio .NET 2003
.NET Framework 3.0 2.0 1.1/ASP.Net 3.0 2.0 1.1/Compact Framework 1.0
SQL Server 2005/2000/SQL Server CE 2.0
If you like, rate this post
Compact Framework for Beginners
-
Oct 9th, 2008, 10:06 PM
#2
Re: Regular expression to find Tokens in HTML page
try this:
vb Code:
Dim rx As New Regex("(?<=\|~)(\d|\w| )*(?=~\|)")
Last edited by .paul.; Oct 9th, 2008 at 10:18 PM.
- Coding Examples:
- Features:
- Online Games:
- Compiled Games:
-
Oct 10th, 2008, 07:41 AM
#3
Re: Regular expression to find Tokens in HTML page
Slight modification to paul's. The whitespace needs to be specified with \s.
Also doing a named capture.
(?<=\|~)(?<tokengesture>(\d|\w|\s)*)(?=~\|)
-
Oct 12th, 2008, 03:02 PM
#4
Thread Starter
Fanatic Member
Re: Regular expression to find Tokens in HTML page
can you please explain the (?<=\\|~) part of the pattern,
i need to replace the entire token, so |~TOKEN~| -> token replacement
Barry
Visual Studio .NET 2008/Visual Studio .NET 2005/Visual Studio .NET 2003
.NET Framework 3.0 2.0 1.1/ASP.Net 3.0 2.0 1.1/Compact Framework 1.0
SQL Server 2005/2000/SQL Server CE 2.0
If you like, rate this post
Compact Framework for Beginners
-
Oct 12th, 2008, 03:09 PM
#5
Re: Regular expression to find Tokens in HTML page
try this:
vb Code:
Dim testStr As String = "eg2: |~Another_Token~|"
MsgBox(Regex.Replace(testStr, "\|~(\d|\w|\s)*~\|", "new String value"))
- Coding Examples:
- Features:
- Online Games:
- Compiled Games:
-
Oct 12th, 2008, 03:34 PM
#6
Thread Starter
Fanatic Member
Re: Regular expression to find Tokens in HTML page
yeah paul, i had changed it to that and it worked, sweet cheers mate...
but one last question why do u put the \ between the ~ and |, when i first changed it i done like \~| what does this backspace mean
Barry
Visual Studio .NET 2008/Visual Studio .NET 2005/Visual Studio .NET 2003
.NET Framework 3.0 2.0 1.1/ASP.Net 3.0 2.0 1.1/Compact Framework 1.0
SQL Server 2005/2000/SQL Server CE 2.0
If you like, rate this post
Compact Framework for Beginners
-
Oct 12th, 2008, 04:00 PM
#7
Re: Regular expression to find Tokens in HTML page
its an escape character. it means to treat the | as a literal character. the | character has special meaning in regex.
- Coding Examples:
- Features:
- Online Games:
- Compiled Games:
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|