473,394 Members | 1,759 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

regex, does not contain

4
Hi Experts,

Wasn't sure where to put this so I followed the posting rules. I'm looking for a regex that gives me the following results:

Example 1:
string = "randomtextrandomtexttotal15.19randomtextrandomtex t"
needed result: "total15.19"

(I managed to do this pretty well, now the one that gives me a problem:)

Example 2:
string = "randomtextrandtextsubtotal15.19randomtextrandomte xt"
needed result: ""

Thanks very much for your feedback.
May 20 '09 #1
8 3966
tlhintoq
3,525 Expert 2GB
Example 2:
Expand|Select|Wrap|Line Numbers
  1. string = "randomtextrandtextsubtotal15.19randomtextrandomte xt"
  2. needed result: ""
  3.  
What am I missing here? You need a way to get a null?
May 20 '09 #2
tfpx
4
No. I need a regex that gives a match in the first example and doesn't match in the second example.
May 20 '09 #3
tlhintoq
3,525 Expert 2GB
Based on what as the criteria?
The only difference I see between example 1 and example 2 is the placement of a space within randomtext (randomte xt) and (randomtex t)

If the text is going to be random, I don't see how it can be used as criteria
May 20 '09 #4
tlhintoq
3,525 Expert 2GB
OH... Is it the difference between total15.19 and subtotal15.19 ??

I wouldn't do it with regex,but that's me.

Expand|Select|Wrap|Line Numbers
  1. If (Mystring.Contains("Subtotal")) return string.Empty;
  2. else
  3. {
  4. // do your regex thing here
  5. }
Just a tip... It helps the reader a lot if you point out the important things in your post especially when it is hidden inside some long string that is easy to gloss over.

Example 1:
string = "randomtextrandomtexttotal15.19randomtextrando mtex t"
needed result: "total15.19"

(I managed to do this pretty well, now the one that gives me a problem:)

Example 2:
string = "randomtextrandtextsubtotal15.19randomtextrand omte xt"
needed result: ""
Example 1:
string = "randomtextrandomtexttotal15.19randomtextrandomtex t"
needed result: "total15.19"

(I managed to do this pretty well, now the one that gives me a problem:)

Example 2:
string = "randomtextrandtextsubtotal15.19randomtextrandomte xt"
needed result: ""
Example 1:
string = "randomtextrandomtexttotal15.19randomtextrandomtex t"
needed result: "total15.19"

(I managed to do this pretty well, now the one that gives me a problem:)

Example 2:
string = "randomtextrandtextsubtotal15.19randomtextrandomte xt"
needed result: ""
More on tags. They're cool. Check'em out.
May 20 '09 #5
tfpx
4
My apologies, I should've give a bit more info. Indeed its the difference between subtotal and total. Isn't it possible to do with a regex?
May 20 '09 #6
tfpx
4
Some more info: The string results from a ocr engine, in most cases it will contain a subtotal and a total. The correct regex would return the total and not the subtotal. With the script you're suggesting this wouldn't work.

Isn't there a way to check what the position is of all the occurences of total in a string, and then check for each occurance if the word is preceded by "sub"?
May 20 '09 #7
tlhintoq
3,525 Expert 2GB
Got me. I spent a day with RegEx to make some methods to confirm IP format and the like, but otherwise haven't used RegEx much.

What code did you use to make the first Total part you say works fine?
May 20 '09 #8
Answer:

(subtotal\s*[\d.]+)|(total\s*[\d.]+)

Your code to check to see if sub group 2 is empty and ignore sub group 1.
May 20 '09 #9

Sign in to post your reply or Sign up for a free account.

Similar topics

5
by: Bill Cohagan | last post by:
I'm looking for help with a regular expression question, so my first question is which newsgroup is the best one to post to? Just in case *this* is the best choice, here's the problem: I'm...
6
by: Vishant | last post by:
Hi, I'm new to javascript and regEx and trying to solve the following problem. I have a function which validates the password if there is a number:...
2
by: Mortimer Schnurd | last post by:
Hi All, I am a VB 6 programmer who is now trying to learn C#. In doing so, I am trying to convert some of my VB modules to C#. I routinely user Reg Expressions in VB and am having some trouble...
17
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 ...
7
by: lgbjr | last post by:
Hi All, I'm trying to split a string on every character. The string happens to be a representation of a hex number. So, my regex expression is (). Seems simple, but for some reason, I'm not...
4
by: shonend | last post by:
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...
11
by: Steve | last post by:
Hi All, I'm having a tough time converting the following regex.compile patterns into the new re.compile format. There is also a differences in the regsub.sub() vs. re.sub() Could anyone lend...
10
by: igor.kulkin | last post by:
I have a small utility program written in Python which works pretty slow so I've decided to implement it in C. I did some benchmarking of Python's code performance. One of the parts of the program...
7
by: Nightcrawler | last post by:
Hi all, I am trying to use regular expressions to parse out mp3 titles into three different groups (artist, title and remix). I currently have three ways to name a mp3 file: Artist - Title ...
4
by: CJ | last post by:
Is this the format to parse a string and return the value between the item? Regex pRE = new Regex("<File_Name>.*>(?<insideText>.*)</File_Name>"); I am trying to parse this string. ...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
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,...
0
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...
0
Oralloy
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,...
0
tracyyun
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...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.