Match between two words
-
Friday, May 11, 2007 6:35 PM
I want to match everything between ANY two word including these two word.
These are the words and I want to include the parenthesis aswell:
(hex)
(str)
Please help with this because I don't know how to sole this
Thanks för all your help and support

Mindraid from Sweden
Answers
-
Friday, May 11, 2007 9:06 PM
to do that u need to match with this regex
\(hex\).*?\(str\)
and replace the match i.e text *** (hex)41303633343630383530202020(str) ***
with an empty str. The result will be
serial number A063460850
don't forget to use SingleLine ON
All Replies
-
Friday, May 11, 2007 6:56 PM
your spec is vague, but this regex
\([^)]*\).*?\([^)]*\)
would match on both words in your input and everything in between them
c# code for regex object: [watch RegexOptions.Singleline]
// using System.Text.RegularExpressions;
/// <summary>
/// Regular expression built for C# on: Fri, May 11, 2007, 02:56:22 PM
/// Using Expresso Version: 2.1.2150, http://www.ultrapico.com
///
/// A description of the regular expression:
///
/// \([^)]*\).*?\([^)]*\)
/// (
/// Any character other than ), any number of repetitions
/// )
/// Any character, any number of repetitions, as few as possible
/// (
/// Any character other than ), any number of repetitions
/// )
///
///
/// </summary>
public static Regex regex = new Regex(
@"\([^)]*\).*?\([^)]*\)",
RegexOptions.IgnoreCase
| RegexOptions.Singleline
); -
Friday, May 11, 2007 7:04 PM
This doesn't require a regular expression.
If want to check if full words match, just compare them.
Adamus
-
Friday, May 11, 2007 8:50 PM
What i meant was that i want to match everything in between the word.
From: (hex) .......To: (str)
Whatever is between these two words i want to match.
Here is an exampel of what I want to do and here is what it looks like:
----------------------------- here is what it looks like---------------------------------
serial number (hex)41303633343630383530202020
(str)A063460850-----------------------------------------------------------------------------------------------
-----------------------------here is how I want it to look like-----------------------
serial number A063460850
-----------------------------------------------------------------------------------------------
So basically I want to clean this "string" in csharp.
Thanks for your help
//Mindraid
-
Friday, May 11, 2007 9:06 PM
to do that u need to match with this regex
\(hex\).*?\(str\)
and replace the match i.e text *** (hex)41303633343630383530202020(str) ***
with an empty str. The result will be
serial number A063460850
don't forget to use SingleLine ON
-
Saturday, May 12, 2007 5:56 AM
Hi
Thanks for your help
This solved my problem

//Mindraid

