Hello,
I have a long string that I need to take a section out of and use.
The section I need always starts with "XX XX XX XX XX"
and always ends with "YY YY YY YY YY"
I want to throw away the rest and use whats between the 2 Marker
strings.
I am not sure how to do this with Regex.
Any help would be appreciated
Thanks,
Mike 7 3322
I believe you're looking for named groups.
your regular expression would look something like "XX XX XX XX
XX(?<data>.*?)Y Y YY YY YY YY"
Then enumerate the matches to find the value for the "data" group in
each one. http://www.regular-expressions.info/named.html
AMP wrote:
Hello,
I have a long string that I need to take a section out of and use.
The section I need always starts with "XX XX XX XX XX"
and always ends with "YY YY YY YY YY"
I want to throw away the rest and use whats between the 2 Marker
strings.
I am not sure how to do this with Regex.
Any help would be appreciated
Thanks,
Mike
(?<=XX XX XX XX XX).*(?=YY YY YY YY YY)
Uses a positive Look-behind, and a positive Look-ahead.
--
HTH,
Kevin Spencer
Microsoft MVP
Chicken Salad Shooter http://unclechutney.blogspot.com
A man, a plan, a canal, a palindrome that has.. oh, never mind.
"AMP" <am******@gmail .comwrote in message
news:11******** *************@c 28g2000cwb.goog legroups.com...
Hello,
I have a long string that I need to take a section out of and use.
The section I need always starts with "XX XX XX XX XX"
and always ends with "YY YY YY YY YY"
I want to throw away the rest and use whats between the 2 Marker
strings.
I am not sure how to do this with Regex.
Any help would be appreciated
Thanks,
Mike
I am new at regex, How do I use this in a statement. I want to operate
on the string between the 2 Markers.
Thnaks
Mike
Kevin Spencer wrote:
(?<=XX XX XX XX XX).*(?=YY YY YY YY YY)
Uses a positive Look-behind, and a positive Look-ahead.
--
HTH,
Kevin Spencer
Microsoft MVP
Chicken Salad Shooter http://unclechutney.blogspot.com
A man, a plan, a canal, a palindrome that has.. oh, never mind.
"AMP" <am******@gmail .comwrote in message
news:11******** *************@c 28g2000cwb.goog legroups.com...
Hello,
I have a long string that I need to take a section out of and use.
The section I need always starts with "XX XX XX XX XX"
and always ends with "YY YY YY YY YY"
I want to throw away the rest and use whats between the 2 Marker
strings.
I am not sure how to do this with Regex.
Any help would be appreciated
Thanks,
Mike
AMP <am******@gmail .comwrote:
Hello,
I have a long string that I need to take a section out of and use.
The section I need always starts with "XX XX XX XX XX"
and always ends with "YY YY YY YY YY"
I want to throw away the rest and use whats between the 2 Marker
strings.
I am not sure how to do this with Regex.
Any help would be appreciated
A quick and dirty example for you:
Regex regex = new Regex(@"^XX XX XX XX XX(?<centervalu e>.+)YY YY YY YY YY");
Match match = regex.Match("XX XX XX XX XXTest StringYY YY YY YY YY");
if (match.Success)
System.Console. WriteLine("Matc hed Text = {0}",
match.Groups[@"centervalu e"].Value);
The output should be "Test String".
--
Thomas T. Veldhouse
Key Fingerprint: 2DB9 813F F510 82C2 E1AE 34D0 D69D 1EDC D5EC AED1
Hi Mike,
The way that the regular expression I posted works is that look-arounds are
non-capturing patterns. They indicate that the pattern indicated must match,
but it is not part of the match. So, to translate my regular expression:
(?<=XX XX XX XX XX).*(?=YY YY YY YY YY)
A match is zero or more of any character. It must be preceded by "XX XX XX
XX XX XX" and it must be followed by "YY YY YY YY YY YY". So that, for
example, in the string:
XX XX XX XX XX123 ABCYY YY YY YY YY
The match will be "123 ABC"
In the string:
XX XX XX XX XX.....YY YY YY YY YY
The match will be "..."
In the string
XX XX XX XX XX123 ABC
There is no match (no "YY..." sequence following)
I'm not sure what the question "How do I use this in a statement" means. But
here is the authoritative Regex reference: http://msdn2.microsoft.com/en-us/lib...ons.regex.aspx
--
HTH,
Kevin Spencer
Microsoft MVP
Chicken Salad Shooter http://unclechutney.blogspot.com
A man, a plan, a canal, a palindrome that has.. oh, never mind.
"AMP" <am******@gmail .comwrote in message
news:11******** *************@m 7g2000cwm.googl egroups.com...
>I am new at regex, How do I use this in a statement. I want to operate
on the string between the 2 Markers.
Thnaks
Mike
Kevin Spencer wrote:
>(?<=XX XX XX XX XX).*(?=YY YY YY YY YY)
Uses a positive Look-behind, and a positive Look-ahead.
-- HTH,
Kevin Spencer Microsoft MVP Chicken Salad Shooter http://unclechutney.blogspot.com
A man, a plan, a canal, a palindrome that has.. oh, never mind.
"AMP" <am******@gmail .comwrote in message news:11******* **************@ c28g2000cwb.goo glegroups.com.. .
Hello,
I have a long string that I need to take a section out of and use.
The section I need always starts with "XX XX XX XX XX"
and always ends with "YY YY YY YY YY"
I want to throw away the rest and use whats between the 2 Marker
strings.
I am not sure how to do this with Regex.
Any help would be appreciated
Thanks,
Mike
Thomas T. Veldhouse wrote:
A quick and dirty example for you:
Regex regex = new Regex(@"^XX XX XX XX XX(?<centervalu e>.+)YY YY YY YY
YY");
Since the OP talks about "a section", this is probably better:
Regex regex = new Regex(@"^.*XX XX XX XX XX(?<centervalu e>.+)YY YY YY YY
YY.*$");
Ebbe
Ebbe Kristensen <eb**@ekologic. dkwrote:
Thomas T. Veldhouse wrote:
>A quick and dirty example for you:
Regex regex = new Regex(@"^XX XX XX XX XX(?<centervalu e>.+)YY YY YY YY YY");
Since the OP talks about "a section", this is probably better:
Regex regex = new Regex(@"^.*XX XX XX XX XX(?<centervalu e>.+)YY YY YY YY
YY.*$");
Agreed.
--
Thomas T. Veldhouse
Key Fingerprint: 2DB9 813F F510 82C2 E1AE 34D0 D69D 1EDC D5EC AED1 This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: engwar1 |
last post by:
Not sure where to ask this. Please suggest another newsgroup if this
isn't the best place for this question.
I'm new to both vb.net and regex. I need a regular expression that will
validate what people are entering as their new password.
Must be between 6 and 10 characters
Must be alphanumeric only
Can not be the word "password" in any case ie "pAsSworD" should also be
denied.
|
by: aevans1108 |
last post by:
expanding this message to microsoft.public.dotnet.xml
Greetings
Please direct me to the right group if this is an inappropriate place
to post this question. Thanks.
I want to format a numeric value according to an arbitrary regular
expression.
|
by: Tim Conner |
last post by:
Hi,
Thanks to Peter, Chris and Steven who answered my previous answer about
regex to split a string. Actually, it was as easy as create a regex with the
pattern "/*-+()," and most of my string was splitted.
I am fascinated to the powerfull use of this RegEx class, so I wonder if it
could go a step further.
As a question, can regex be used to valid a set of different functions ?
Example : Suppose I have to verify the correctness of an...
|
by: Du Dang |
last post by:
Text:
=====================
<script1>
***stuff A
</script1>
***more stuff
<script2>
***stuff B
|
by: clintonG |
last post by:
I'm using an .aspx tool I found at but as nice as the interface is I
think I need to consider using others. Some can generate C# I understand.
Your preferences please...
<%= Clinton Gallagher
http://forta.com/books/0672325667/
| |
by: Chris |
last post by:
How Do I use the following auto-generated code from The Regulator?
'------------------------------------------------------------------------------
' <autogenerated>
' This code was generated by a tool.
' Runtime Version: 1.1.4322.2032
'
' Changes to this file may cause incorrect behavior and will be lost if
' the code is regenerated.
' </autogenerated>
|
by: Martin Evans |
last post by:
Sorry, yet another REGEX question. I've been struggling with trying to get
a regular expression to do the following example in Python:
Search and replace all instances of "sleeping" with "dead".
This parrot is sleeping. Really, it is sleeping.
to
This parrot is dead. Really, it is dead.
|
by: Extremest |
last post by:
I am using this regex.
static Regex paranthesis = new Regex("(\\d*/\\d*)",
RegexOptions.IgnoreCase);
it should find everything between parenthesis that have some numbers
onyl then a forward slash then some numbers. For some reason I am not
getting that. It won't work at all in 2.0
|
by: Phil Barber |
last post by:
I am using Regex to validate a file name. I have everything I need except I
would like the dot(.) in the filename only to appear once. My question is it
possible to allow one instance of character but not two or more?
example
myfile.doc = good
My.file.doc = not good
if you could give an example of the expression pattern that would most
helpful.
thanks
phil
|
by: |
last post by:
Hi all,
Sorry for the lengthy post but as I learned I should post
concise-and-complete code.
So the code belows shows that the execution of ValidateAddress consumes a
lot of time. In the test it is called a 100 times but in my real app it
could be called 50000 or more times.
So my question is if it is somehow possible to speed this up and if so how
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
| |
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
| |
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
|
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |