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 "LOT:". Source text
may contain multiple "SUB: ... LOT:" blocks.
For example this is my source text:
SUB: this text I want to extract LOT: 2345 , something in between, new
SUB: again something I want to extract LOT: 2145 and more text here,
the end
When I apply this pattern:
SUB:\s+[^\r\n]+\s+LOT:\s+[^\r\n\s]+
in .NET's Regex.Matches(...), I only get one match:
SUB: this text I want to extract LOT: 2345 , something in between, new
SUB: again something I want to extract LOT: 2145
Obviously, something in this regex tells it to be "greedy", and I need
the partial matches too.
I thought this pattern would return ALL matches, which are:
1) SUB: this text I want to extract LOT: 2345
2) SUB: again something I want to extract LOT: 2145
3) SUB: this text I want to extract LOT: 2345 , something in between,
new SUB: again something I want to extract LOT: 2145
The last one I don't need of course, but I can handle it - ignore it,
and use only the first two.
So my idea was to modify my pattern to read like this:
give me all matches resembling text between "SUB:" and "LOT:",
including those keywords, plus one word after "LOT:", but (!) the text
between cannot contain "LOT:"
If I manage to compose such RegEx pattern, it would even eliminate the
result 3), and return only what I really need. But the problem is how
to define pattern that will eliminate (exclude) the whole word. I
tried "[^ ... ]" pattern, but that works only for single characters
listed between the brackets.
For example:
SUB:\s+[^\r\n(LOT:)]+\s+LOT:\s+[^\r\n\s]+
is not working. I thought that "( )" brackets would group the
characters and tell the regex not the match the appearance of the whole
word "LOT:". But instead, it invalidates any text that contain any of
these characters:
) ( : L T O
So if you could answer at least one of the following questions, I would
appreciate it very much:
1) generally, how do you compose the regex pattern to not match the
text that contain certain word?
2) if there is no easy solution for 1), or there is a better solution
for the problem I described above, what is it?
Thank you so much!
Shone 4 3480
Hello,
Have you tried something like this
(sub:(.)*LOT:(.)+?\s)
Let me know if it solved your problem.
-------------------- From: sh*****@yahoo.com Newsgroups: microsoft.public.dotnet.general Subject: HowTo? RegEx - pattern to exclude the whole word Date: 8 Feb 2006 11:01:28 -0800 Organization: http://groups.google.com Lines: 67 Message-ID: <11*********************@g43g2000cwa.googlegroups. com> NNTP-Posting-Host: 63.86.206.3 Mime-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" X-Trace: posting.google.com 1139425293 27748 127.0.0.1 (8 Feb 2006
19:01:33 GMT)X-Complaints-To: gr**********@google.com NNTP-Posting-Date: Wed, 8 Feb 2006 19:01:33 +0000 (UTC) User-Agent: G2/0.2 X-HTTP-UserAgent: Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1;
NET CLR 1.1.4322),gzip(gfe),gzip(gfe)Complaints-To: gr**********@google.com Injection-Info: g43g2000cwa.googlegroups.com; posting-host=63.86.206.3; posting-account=FAgaQQwAAABNdEbvXlMQ8kQ3uQ0Iry25 Path:
TK2MSFTNGXA01.phx.gbl!TK2MSFTNGP08.phx.gbl!newsfee d00.sul.t-online.de!t-onli
ne.de!news.glorb.com!postnews.google.com!g43g2000c wa.googlegroups.com!not-fo
r-mailXref: TK2MSFTNGXA01.phx.gbl microsoft.public.dotnet.general:188343 X-Tomcat-NG: microsoft.public.dotnet.general
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 "LOT:". Source text may contain multiple "SUB: ... LOT:" blocks.
For example this is my source text:
SUB: this text I want to extract LOT: 2345 , something in between, new SUB: again something I want to extract LOT: 2145 and more text here, the end
When I apply this pattern:
SUB:\s+[^\r\n]+\s+LOT:\s+[^\r\n\s]+
in .NET's Regex.Matches(...), I only get one match:
SUB: this text I want to extract LOT: 2345 , something in between, new SUB: again something I want to extract LOT: 2145
Obviously, something in this regex tells it to be "greedy", and I need the partial matches too.
I thought this pattern would return ALL matches, which are: 1) SUB: this text I want to extract LOT: 2345 2) SUB: again something I want to extract LOT: 2145 3) SUB: this text I want to extract LOT: 2345 , something in between, new SUB: again something I want to extract LOT: 2145
The last one I don't need of course, but I can handle it - ignore it, and use only the first two.
So my idea was to modify my pattern to read like this: give me all matches resembling text between "SUB:" and "LOT:", including those keywords, plus one word after "LOT:", but (!) the text between cannot contain "LOT:"
If I manage to compose such RegEx pattern, it would even eliminate the result 3), and return only what I really need. But the problem is how to define pattern that will eliminate (exclude) the whole word. I tried "[^ ... ]" pattern, but that works only for single characters listed between the brackets. For example:
SUB:\s+[^\r\n(LOT:)]+\s+LOT:\s+[^\r\n\s]+
is not working. I thought that "( )" brackets would group the characters and tell the regex not the match the appearance of the whole word "LOT:". But instead, it invalidates any text that contain any of these characters: ) ( : L T O
So if you could answer at least one of the following questions, I would appreciate it very much:
1) generally, how do you compose the regex pattern to not match the text that contain certain word? 2) if there is no easy solution for 1), or there is a better solution for the problem I described above, what is it?
Thank you so much!
Shone
--
Thank You,
Nanda Lella,
This Posting is provided "AS IS" with no warranties, and confers no rights.
Unfortunately not.
It returns the same result (only one match) as my original pattern.
thanks
Foud it!
Actually it's more a work-around than a solution, but as long as it
works...
The approach: natural ingenuity and ancient wisdom: "if you can't beat
them - join them!".
So RegEx doesn't have required pattern, i.e. [^...] pattern requires
single character. OK, I'll give it a single character. Simply replace
all occurences of the keyword "LOT:" in the source string with one
single character. Only have to be careful to pick the one that
certainly will not appear as a regular character contained in original
text. In this case ~ (tilda) is fine. So the regex pattern is:
SUB:\s+[^\r\n~]+\s+~\s+[^\r\n\s]+
Applied to modified source text it returns me exactly what I want.
Thanks for looking, take care...
Shone
Glad to see that you figured it out.
and; by the way (SUB:(.)*LOT:(.)+?\s) works for me.
I dont know how you are implementing it. I used case insensitive and
multiline options. And it returned follwing results.
+ Match [0] SUB: this text I want to extract LOT: 2345
+ Match [1] SUB: again something I want to extract LOT: 2145
-------------------- From: sh*****@yahoo.com Newsgroups: microsoft.public.dotnet.general Subject: Re: HowTo? RegEx - pattern to exclude the whole word Date: 9 Feb 2006 08:03:36 -0800 Organization: http://groups.google.com Lines: 20 Message-ID: <11**********************@g14g2000cwa.googlegroups .com> References: <11*********************@g43g2000cwa.googlegroups. com> NNTP-Posting-Host: 63.86.206.3 Mime-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" X-Trace: posting.google.com 1139501021 6216 127.0.0.1 (9 Feb 2006 16:03:41
GMT)X-Complaints-To: gr**********@google.com NNTP-Posting-Date: Thu, 9 Feb 2006 16:03:41 +0000 (UTC) In-Reply-To: <11*********************@g43g2000cwa.googlegroups. com> User-Agent: G2/0.2 X-HTTP-UserAgent: Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1;
NET CLR 1.1.4322),gzip(gfe),gzip(gfe)Complaints-To: gr**********@google.com Injection-Info: g14g2000cwa.googlegroups.com; posting-host=63.86.206.3; posting-account=FAgaQQwAAABNdEbvXlMQ8kQ3uQ0Iry25 Path:
TK2MSFTNGXA01.phx.gbl!TK2MSFTFEED02.phx.gbl!tornad o.fastwebnet.it!tiscali!ne
wsfeed1.ip.tiscali.net!news.glorb.com!postnews.goo gle.com!g14g2000cwa.google
groups.com!not-for-mailXref: TK2MSFTNGXA01.phx.gbl microsoft.public.dotnet.general:188428 X-Tomcat-NG: microsoft.public.dotnet.general
Foud it! Actually it's more a work-around than a solution, but as long as it works...
The approach: natural ingenuity and ancient wisdom: "if you can't beat them - join them!". So RegEx doesn't have required pattern, i.e. [^...] pattern requires single character. OK, I'll give it a single character. Simply replace all occurences of the keyword "LOT:" in the source string with one single character. Only have to be careful to pick the one that certainly will not appear as a regular character contained in original text. In this case ~ (tilda) is fine. So the regex pattern is:
SUB:\s+[^\r\n~]+\s+~\s+[^\r\n\s]+
Applied to modified source text it returns me exactly what I want.
Thanks for looking, take care... Shone
--
Thank You,
Nanda Lella,
This Posting is provided "AS IS" with no warranties, and confers no rights. This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: Seb |
last post by:
Hi,
Has anyone an idee how i can replace every character in a string if it is not alphanumeric ?
something like eregi_replace, but i don't know how i say in regex NOT.
Tnx
|
by: Xah Lee |
last post by:
http://python.org/doc/2.4.1/lib/module-re.html
http://python.org/doc/2.4.1/lib/node114.html
---------
QUOTE
The module defines several functions, constants, and an exception. Some
of the...
|
by: Ali Eghtebas |
last post by:
Hi,
I've made this regex to catch the start of a valid multiline comment such as
"/*" in e.g. T-SQL code.
"(?<=^(?:*'*')*?*)(?<!^(?:*'*')*?--.*)/\*.*?$"
With Multiline option on.
As we know...
|
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...
|
by: Razzie |
last post by:
Hey all,
Decided to give a shot at Regular expressions - need a bit of help :)
I can't seem to find the right regex for matching words like "*test*" or
*somevalue*" - in short, all words...
|
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
...
|
by: Mark |
last post by:
I must create a routine that finds tokens in small, arbitrary VB code
snippets. For example, it might have to find all occurrences of
{Formula}
I was thinking that using regular expressions...
|
by: Lubomir |
last post by:
Hi,
I am using the following pattern:
"\\b" + MySttring + "\\b"
If MyString is "one", this should pick up whole words like "one".
The problem is, it will pick up also the word: "one.two"...
|
by: james_027 |
last post by:
hi,
how do I regex that could check on any of the value that match any one
of these ... 'jan', 'feb', 'mar', 'apr', 'may', 'jun', 'jul', 'aug',
'sep', 'oct', 'nov', 'dec'
Thanks
james
|
by: antdb |
last post by:
Ⅰ. Advantage of AntDB: hyper-convergence + streaming processing engine
In the overall architecture, a new "hyper-convergence" concept was proposed, which integrated multiple engines and...
|
by: Arjunsri |
last post by:
I have a Redshift database that I need to use as an import data source. I have configured the DSN connection using the server, port, database, and credentials and received a successful connection...
|
by: WisdomUfot |
last post by:
It's an interesting question you've got about how Gmail hides the HTTP referrer when a link in an email is clicked. While I don't have the specific technical details, Gmail likely implements measures...
|
by: Matthew3360 |
last post by:
Hi,
I have been trying to connect to a local host using php curl. But I am finding it hard to do this. I am doing the curl get request from my web server and have made sure to enable curl. I get a...
|
by: Oralloy |
last post by:
Hello Folks,
I am trying to hook up a CPU which I designed using SystemC to I/O pins on an FPGA.
My problem (spelled failure) is with the synthesis of my design into a bitstream, not the C++...
|
by: BLUEPANDA |
last post by:
At BluePanda Dev, we're passionate about building high-quality software and sharing our knowledge with the community. That's why we've created a SaaS starter kit that's not only easy to use but also...
|
by: Ricardo de Mila |
last post by:
Dear people, good afternoon...
I have a form in msAccess with lots of controls and a specific routine must be triggered if the mouse_down event happens in any control.
Than I need to discover what...
|
by: Johno34 |
last post by:
I have this click event on my form. It speaks to a Datasheet Subform
Private Sub Command260_Click()
Dim r As DAO.Recordset
Set r = Form_frmABCD.Form.RecordsetClone
r.MoveFirst
Do
If...
|
by: jack2019x |
last post by:
hello, Is there code or static lib for hook swapchain present?
I wanna hook dxgi swapchain present for dx11 and dx9.
| |