Regex - Extract SubString Based On Regular Expression Match
Apr 26, 2012Quick RegExp problem (i hope). I need to identify a sub string from any string based on a regular expression. For Example, take the following strings:
[Code]...
Quick RegExp problem (i hope). I need to identify a sub string from any string based on a regular expression. For Example, take the following strings:
[Code]...
I am pretty good with perl regular expressions but evidently I am at a loss on why this doesn't work.The code below stores "Person Test" in output variable.
im output As String
Dim userName As String = "Test, Person"
Dim re As New Regex("(w+),s(w+)", RegexOptions.Singleline)
output = re.Replace(userName, "$2 $1")
So why doesn't the following code store "#Test##Person#" in output variable.
Dim output As String
Dim userName As String = "Test, Person"
Dim re As New Regex("(w+),s(w+)")
For Each Match As Match In re.Matches(userName)
output &= "#" & Match.ToString & "#"
Next
I am trying to separate numbers from a string which includes %,/,etc for eg (%2459348?:, or :2434545/%). How can I separate it, in VB.net
View 4 RepliesI'd like to be able to match a specific sequence of characters, starting with a particular substring and ending with a particular substring. My positive lookahead regex works if there is only one instance to match on a line, but not if there should be multiple matches on a line. I understand this is because (.+) captures up everything until the last positive lookahead expression is found. It'd be nice if it would capture everything until the first expression is found.
Here is my regex attempt:
@@FOO[(.*)(?=~~)~~(.*)(?=]@@)]@@
Sample input:
@@FOO[abc~~hi]@@ @@FOO[def~~hey]@@
Desired output: 2 matches, with 2 matching groups each (abc, hi) and (def, hey).
Actual output: 1 match with 2 groups (abc~~hi]@@ @@FOO[def, hey)
Is there a way to get the desired output?
How do I make a regular expression to find a substring within a string that looks like: |sdrt446-7fdfs23| ? The number of characters and types change. So I need whatever in within the | |.
View 3 RepliesI want to match a string for example "yes" but where it is not in brackets so that the following would be matched: yes (bla yes bla) bla yes
View 7 RepliesHow can I match the domain part only of a URI with regular expressions? I see lots of examples but the mutch the subdomain too. What I am looking to do is to capture only the domain. So, for example [URL] should match only google. As a secondary question, I am looking to implement this on a VB.NET program. Would there be some other way to do it without regular expressions?
View 2 RepliesI want a regular expression for the following issue:I want to match a string that contains A,B,C,D,E and F. string length should be 0 to 6. and not character should be repeat in the string.Example: ABCDEF, ACDEFB, EFBCDA, etc. but not ABBCDES/W Engineer
View 3 RepliesI would like to match a certain url from an html page using a regular expression. For example I only want the url that appears after the <h2 header in the html page.basically here is the url I want to match; so what would the regular expression look like.
<h2 style="display: block"><a href="http://url.com/">url</a></h2>
I have matched the href part, but I only need to pull this particular one on the page that appears after the h2 header.
I want to match whole words for any kinds of strings, my
Text: to happening behitond .to.the to curtains of this .<NET> open <NET> sou<NET>rce project.<NET>
now i have tried this to find "<NET>" (without quotes) the whole word with[code]...
Is it possible to use regex with Range.Find.Text or set the Word.Range according to a regex in word automation? I just want to find strings that match a regular expression an manipulate them.
View 2 RepliesMy coworker needs me to write him a regular expression for his vb.net app.I do not know vb and he does not know regex.The regex he needs is:/.*web id: ?(d+).*/iBasically he needs to search a string for something like "web id: 345" or "web id:2534" and retrieve the ID.He took what I gave him above and was able to put this together:
Dim strPattern As String = ".*web id: ?(d+).*"
Dim strReplacement$ = "$1"
GetWebId$ = Regex.Replace(LCase$(strNote$), strPattern$, strReplacement$)
[code].....
I want to extract a URL value from an INI File as such:
[DEFAULT]
BASEURL=http://www.stackoverflow.com/
[InternetShortcut]
URL=http://www.stackoverflow.com/
So I can get the URL value as the only Match from the Regular expression - but I don't understand enough about them (yet) to do this. I have seen RegEx examples that will parse any INI file and get the Name, Value Pairs I just want to get the URL value only from a file no matter what else it contains. My aim is to have something like this:
Dim _pattern As New Text.RegularExpressions.Regex("RegEx")
Dim _url As String = _pattern.Match(iniContentString).Value
It seems simple but I cannot seem to create a specific case RegEx where I want everything from "URL=" to the vbCrLf at the End to be my "Match". I have refered to Regular-Expressions.info which has been a help before but still cannot get this simple example to work.
I am trying to write a regular expression string match in vb.net. The condition that I am trying to implement is that the string should contain only alphabets and must contain atleast one letter of both lower and upper case. i.e AAA-fail, aaa-fail, aAaA-pass.
The regular expression that I have come up with is ^(([a-z]+[A-Z]+)+|([A-Z]+[a-z]+)+)$
Does anyone have a regurlar expression available which only accepts dates in the format dd/mm/yy but also has strict checking to make sure that the date is valid, including leap year support?
I am coding in vb.net and am struggling to work this one out.
I want regular expression validator for my telephone field in VB.net. Telephone format should be (+)xx-(0)xxxx-xxxxxx ext xxxx (Optional) example my number would appear as 44-7966-591739 Screen would be formatted to show +44-(0)7966-591739 ext?
View 3 RepliesI'm trying to type a regular expression that follows the following format: [URL] There are no special characters or numbers permitted for this criteria. I thought I had it down, but I'm a bit rusty with regular expressions and when I tested mine, it failed all across the boards. So far, my regular is expression is:
[Code]...
I've got a question about Regular Expression in Visual Basic. I normally program in PHP and I can do the following in PHP, is this also possible in VB? Text to match:
user-123456:3a9va6
user-748538:870fas
user-384593:fs8s9s
user-575432:0das0d
Then I can use the following Regular Expression to extract the username and password:
(user-[0-9]{6}).*([a-z0-9]{6})
If I use it with the following php code, it generates a 2-dimensional array with every user and it's password in the $matches array:
PHP
preg_match_all("/(user-[0-9]{6}).*([a-z0-9]{6})/siU", $input, $matches, PREG_SET_ORDER)
Then I'm able to loop through all user and their username:
PHP
foreach($matches as $match)
{
echo $match[0].":".$match[1];
}
I would like to extract the word "date" from a string. It could appear as "DATE". "the date", "datee", "the_Date" or any other form
View 7 Repliesok, For the moment I have a string() where each element is in the structure of
[Code]...
I'm trying to find the right RegEx to capture some (potentially) repeating data. I don't know how many times it will repeat. If I give an exanple of the data and what I want to capture can anyone point me in the right direction? It's the .Net regex engine (Visual Basic)
[Code]...
Excel returns a reference of the form
=Sheet1!R14C1R22C71junk
("junk" won't normally be there, but I want to be sure that there's no extraneous text.)I would like to 'split' this into a VB array, where
a(0)="Sheet1"
a(1)="14"
a(2)="1"
[code]....
I'm sure it can be done easily with a regular expression, but I just can't get the hang of it.
I need a regular expression that requires at least ONE digits and SIX maximum. I've worked out this, but neither of them seems to work. ^[0-9][0-9]?[0-9]?[0-9]?[0-9]?[0-9]?$ ^[0-999999]$
View 4 RepliesIt seems up until now I've never used Regex, nor even heard of it. But once I did I realized how extremely useful this is. Having said, it's been 2 days since I've began looking into constructing my own patterns. My most recent being for decimals. Is the pattern I provided below "proper"? and are there also any improvements I could be making for a more efficient patter, which would minimize any possibility of a loophole? [code] So for my use, this is doing what it's supposed to being doing under every test I can through at it. But do mind the 0. and .0, I have a function to normalize these as they are proper, I just pad the left and right accordingly. I found most regex questions asked here..and yes I am doing this in vb.net so it fits. If not, then feel free to move this post somewhere else better suited for the topic of discussion.
View 12 Repliesregex - regular expression to check input on multiline textbox
View 5 RepliesThis is a related to a previous question I have asked here, see the link below for a brief description as to why I am trying to do this.Regular expression from font to span (size and colour) and back (VB.NET).Basically I need a regex replace function (or if this can be done in pure VB then that's fine) to convert all ul tags in a string to textindent tags, with a different attribute value for the first textindent tag.For example:
<ul>
<li>This is some text</li>
<li>This is some more text</li>[code].....
Basically I want the first ul tag to have no indenting, but all nested ul tags to have an indent of 20.
I have written code to pull some data into a data table and do some data re-formatting. I need some help splitting some text into appropriate columns.
CASE 1
I have data formated like this that I need to split into 2 columns.
[Code]...
column is the first 11 characters That is easy.column 2 should contain all the text after the first 11 characters up to but not including the first number.The last column is all the text after column 2
I know it may be quite easily for you. i have a text which contains 40 lines, I want to remove lines which starts with a constant text. check below data.
When I used (?mn)[+CMGL:].*($) it removes the whole text , when I use (?mn)[+CMGL:].*(
) , it only leaves the first line.
+CMGL: 0,1,,159
07910201956905F0440B910201532762F20008709021225282808
+CMGL: 1,1,,159
[Code]...
I'm using Visual Basic 2010 Express to edit an XML file. I want to replace items that have (typically) non-zero floating point numbers with a single zero.
View 4 RepliesI'm trying to replace all the carriage return characters in a string obtained from a multi line text box in a Windows Form with the string ", <BR>" so that when I use the string in some HTML it displays correctly.
Function Blah(ByVal strInput As String) As String
Dim rexCR As Object
rexCR = CreateObject("VBScript.RegExp")
[code]....