473,378 Members | 1,527 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,378 software developers and data experts.

Getting variable in a pattern using Regex

Hi,
I have a string with some fixed text and variable text.
For example: "this is a fixed text THE NEEDED INFO more more fixed text".
How do I get the the variable text (THE NEEDED INFO) from this string ?
A simple example will help.

Thanks.
ra***@hotmail.com
Nov 21 '05 #1
4 3051
Dim txt As String
txt = "this is a fixed text THE NEEDED INFO more more fixed text"
txt = Mid(txt, 23, txt.Length - 22)

23 <- starting index
txt.Length - 22 <- size of your NEEDED INFO

"Ya Ya" wrote:
Hi,
I have a string with some fixed text and variable text.
For example: "this is a fixed text THE NEEDED INFO more more fixed text".
How do I get the the variable text (THE NEEDED INFO) from this string ?
A simple example will help.

Thanks.
ra***@hotmail.com

Nov 21 '05 #2
Thanks, but I am looking for example using REGEX.

ra***@hotmail.com

"Alex Levi" <Al******@discussions.microsoft.com> wrote in message
news:44**********************************@microsof t.com...
Dim txt As String
txt = "this is a fixed text THE NEEDED INFO more more fixed text"
txt = Mid(txt, 23, txt.Length - 22)

23 <- starting index
txt.Length - 22 <- size of your NEEDED INFO

"Ya Ya" wrote:
Hi,
I have a string with some fixed text and variable text.
For example: "this is a fixed text THE NEEDED INFO more more fixed text".
How do I get the the variable text (THE NEEDED INFO) from this string ?
A simple example will help.

Thanks.
ra***@hotmail.com

Nov 21 '05 #3
Dim text As String = "One car red car blue car"
Dim pat As String = "(\w+)\s+(car)"
' Compile the regular expression.
Dim r As Regex = new Regex(pat, RegexOptions.IgnoreCase)
' Match the regular expression pattern against a text string.
Dim m As Match = r.Match(text)
Dim matchcount as Integer = 0
While (m.Success)
matchCount += 1
Console.WriteLine("Match" & (matchCount))
Dim i As Integer
For i = 1 to 2
Dim g as Group = m.Groups(i)
Console.WriteLine("Group" & i & "='" & g.ToString() & "'")
Dim cc As CaptureCollection = g.Captures
Dim j As Integer
For j = 0 to cc.Count - 1
Dim c As Capture = cc(j)
Console.WriteLine("Capture" & j & "='" & c.ToString() _
& "', Position=" & c.Index)
Next j
Next i
m = m.NextMatch()
End While
chanmm
"Ya Ya" <ra***@hotmail.com> wrote in message
news:uU*************@TK2MSFTNGP12.phx.gbl...
Thanks, but I am looking for example using REGEX.

ra***@hotmail.com

"Alex Levi" <Al******@discussions.microsoft.com> wrote in message
news:44**********************************@microsof t.com...
Dim txt As String
txt = "this is a fixed text THE NEEDED INFO more more fixed text"
txt = Mid(txt, 23, txt.Length - 22)

23 <- starting index
txt.Length - 22 <- size of your NEEDED INFO

"Ya Ya" wrote:
Hi,
I have a string with some fixed text and variable text.
For example: "this is a fixed text THE NEEDED INFO more more fixed
text".
How do I get the the variable text (THE NEEDED INFO) from this string ?
A simple example will help.

Thanks.
ra***@hotmail.com


Nov 21 '05 #4
On 2004-10-23, Ya Ya <ra***@hotmail.com> wrote:
Hi,
I have a string with some fixed text and variable text.
For example: "this is a fixed text THE NEEDED INFO more more fixed text".
How do I get the the variable text (THE NEEDED INFO) from this string ?
A simple example will help.


Assuming you want to match by the surrounding text (as opposed to
matching all case, or whatever)...
Private Function DoMatch(ByVal input As String) As String
Dim pattern As String = "fixed text ([\w ]+) more more fixed text"

Dim match As System.Text.RegularExpressions.Match = _
System.Text.RegularExpressions.Regex.Match(input, pattern)

If match.Length > 0 Then
Return match.Groups(1).Value
Else
Return Nothing
End If

End Function
Nov 21 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Er Galv?o Abbott | last post by:
Greetings. I have a function that does some pattern matching with JS's RegEx and I'm trying to use a variable inside of it. Nothing that I've done worked, so please help me. Here is the func:...
2
by: Pierre | last post by:
Hello, I would like to write a regexp that can be either case sensitive or that can ignore the case based on a variable (value would be either 'i' or ''). For instance in the below code the...
4
by: Jozef Jarosciak | last post by:
Hi everyone, I am building a web crawler and one of the features which I need to include is exclusion of specified 'variable + value' from the url. Example, user wanted to extract variable...
4
by: Friday | last post by:
Being an Old L.A.M.P guy, I beg you to please excuse my ignorance of dot.net (and all things Windows, for that matter). As part of an experiment (to learn enough ASP/VB.net to port a series of ...
2
by: Ed Brown | last post by:
I'm working on a VB.Net application that needs to do quite a bit of string pattern matching, and am having problems using the "LIKE" operator to match the same string twice in the pattern. For...
5
by: Jason | last post by:
Is there a mechanism in VB.NET that allows something like: If myVar In ("A","B","C") Then... The way I'm doing it now is: Select Case myVar Case "A","B","C" Or like this:
4
by: shonend | last post by:
I am trying to extract the pattern like this : "SUB: some text LOT: one-word" Described, "SUB" and "LOT" are key words; I want those words, everything in between and one word following the...
8
by: sherifffruitfly | last post by:
Hi, I've been searching as best I can for this - coming up with little. I have a file that is full of lines fitting this pattern: (?<year>\d{4}),(?<amount>\d{6,7}) I'm likely to get a...
1
by: faultykid | last post by:
I would like to store a variable then call it back later. I have a variable on line 198 www = ''+this._ad.clickUrl+''; and on line 321 i try document.write(www);
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.