I have the following text inside a file which I am trying to parse.
I am creating a new RegEx object as follows :-
string strRegex = @"({S:\r?\n) ([^}]*)(})"
{S: INTERLOCK FAIL : Tie bar hoist - rotate anticlockwise
I1-T/bar hoist slew handwind eng, input LS/TBHS/HWEa is
LOW
I1-T/bar hoist slew handwind eng, input LS/TBHS/HWEb is
HIGH
}
Calling the match method of strRegex provides no matches, however if I
move 'INTERLOCK FAIL' onto a new line and ensure there is no space
after the '{S:' the match method returns the text I am looking for.
For the life of me I cannot fathom out the expression required to
capture text regardless of whether it is on the same line as the {S:
or not and also if there is white space after the {S:.
I could manually restructure the text if it was only a few changes,
trouble is I have over 1000 files each containing possibly 100s of
these text messages.
Can anoyone out there shed some light on the problem.
Thanks 1 1312
* bi**********@sc omagg.com wrote, On 29-6-2007 16:12:
I have the following text inside a file which I am trying to parse.
I am creating a new RegEx object as follows :-
string strRegex = @"({S:\r?\n) ([^}]*)(})"
{S: INTERLOCK FAIL : Tie bar hoist - rotate anticlockwise
I1-T/bar hoist slew handwind eng, input LS/TBHS/HWEa is
LOW
I1-T/bar hoist slew handwind eng, input LS/TBHS/HWEb is
HIGH
}
Calling the match method of strRegex provides no matches, however if I
move 'INTERLOCK FAIL' onto a new line and ensure there is no space
after the '{S:' the match method returns the text I am looking for.
For the life of me I cannot fathom out the expression required to
capture text regardless of whether it is on the same line as the {S:
or not and also if there is white space after the {S:.
I could manually restructure the text if it was only a few changes,
trouble is I have over 1000 files each containing possibly 100s of
these text messages.
Can anoyone out there shed some light on the problem.
string strRegex = @"({S:\r?\n) ([^}]*)(})"
Your current regex reads as follows:
find the following text: {S:
optionally find a carrige return (\r?)
find a newline (\n)
find any text that is not a } [^}]*
find the closing bracket }
It also contains a lot of ( and ) that I think only make it less readable.
I'd try this alternative:
{S:(?<content>[^}]*)}
Or if you don't want any leading spaces/tabs/newlines:
{S:\s*(?<conten t>[^}]*)}
which reads as follows:
find {S:
optionally find any number whitespace characters (\s*)
find and capture any text that is not a } ([^}]*) in a named group
called "content"
find a closing bracket (})
To get the value from the parsed text you can then use the following code:
Regex rx = new Regex(@"{S:\s*([^}]*)}");
Match m = rx.Match(".... text to match .....");
string match = m.Value;
string content = m.Groups["content"].Value;
Jesse Houwing This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: alphatan |
last post by:
Is there relative source or document for this purpose?
I've searched the index of "Mastering Regular Expression", but cannot
get the useful information for C.
Thanks in advanced.
--
Learning is to improve, but not to prove.
|
by: H |
last post by:
This is kind of an followup on oneof my previous questions, and it has with
RegEx to do.
I have a string containing of several words. What would a good regex
expression looklike to get one match on every word ?
For example :
String myString =" This is the string that stupid H can't split up";
// A good RegEx needed here .. So the result would look something like this
;
|
by: D |
last post by:
My first attempt at this and I'm searching formulas like so
RIGHT(TEXT(A15,'yy'),1)*1000+A15-CONCATENATE(1,'-','jan','-',TEXT(A15,'yy'))+1
I want to extract the row / col coordinates (A15 in above)
so I'm using this +\d+\d*
however I want unique ones and not 3 copies of A15 as the above returns.
|
by: steve |
last post by:
here's the deal...cvs, tick encapsulted data. trying to use regex's to
validate records. here's an example row:
'AD,'BF','132465','06/09/2004','','BNSF','A','TYPE','1278','','BR','2999',''
,'LX','','01','09','1','','','','','','','','','CUSTOM JOB CODE TEST'
record type is in the 8th column ('1278'). using regex b/c there are a
miriad of types that cause other data w/n the record (or related records) to
be in/valid. i'm having problems...
|
by: Ya Ya |
last post by:
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.
ra294@hotmail.com
| |
by: lgbjr |
last post by:
Hello All,
I have the following type of string: "X:Y\Z.exe" "123"
What I need is an array of strings with the information from within each set
of quotes. I was trying to use a Regex.Split, but I can't figure out how to
escape a quote. The closest I got was Regex.split(String,"(\"")"), which
gives me an array of strings:
"X:Y\Z.exe
|
by: Chris Lieb |
last post by:
I am trying to write a regex that will parse BBcode into HTML using
JavaScript. Everything was going smoothly using the string class
replace() operator with regex's until I got to the list tag.
Implementing the list tag itself was fairly easy. What was not was
trying to handle the list items. For some reason, in BBcode, they
didn't bother defining an end tag for a list item. I guess that they
designed it with bad old HTML 3.2 in mind...
|
by: ad |
last post by:
I am useing VS2005 to develop wep application.
I use a RegularExpress both in RegularExpressionValidator and Regex class to
validate a value.
The RegularExpress is 20|\-9|\-1|?\d{1}
When I enter 33 and validate with RegularExpressionValidator, it fail to
pass.
But when I validate with regex class :
Regex.IsMatch(Sight0L, @"20|\-9|\-1|?\d{1}");
|
by: |
last post by:
I'm analyzing large strings and finding matches using the Regex class. I
want to find the context those matches are found in and to display excerpts
of that context, just as a search engine might. In terms of code, what's the
easiest way to make that happen? The code below works fine for identifying
the matches, but it doesn't try to extract the surrounding context or
display it:
currPageText =
numberOfMatches =...
|
by: Flomo Togba Kwele |
last post by:
I am having difficulty writing a Regex constructor.
A line has a quote(") at its beginning and its end. I need to strip both characters off. If the
line looks like "1", I need the result to be 1.
If it were sed, I could just do s/^"// and s/"$//, but I'm confused with the quote escape
characters. Also, can I do both replacements at once?
I tried:
|
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: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
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: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
| |
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.
| |