473,569 Members | 2,721 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Regular express question

I have the following words, and I want to extract the first part and the
trailing numbers.

OP001 =ABC, 001
ST02 =CD, 02
00A =00A, null

I have the following regular express:
(?<first>.*?)(? <second>\d+)
This one works well for the given first two examples but not the third one.

And (?<first>.*?)(? <second>\d+)$ returns strange result.

Jul 16 '07 #1
5 2002
I'm unfamiliar with the <first<secondsy ntax you're using, but the
following regular expression works for the three samples given:

Regex.Replace(" OP001", @"(.*\D+)(\d*)" , @"$1, $2"); // Returns: "OP, 001"
Regex.Replace(" ST02", @"(.*\D+)(\d*)" , @"$1, $2"); // Returns: "CD, 02"
Regex.Replace(" 00A", @"(.*\D+)(\d*)" , @"$1, $2"); // Returns: "00A, "
"Matt" <Ma**@discussio ns.microsoft.co mwrote in message
news:FC******** *************** ***********@mic rosoft.com...
>I have the following words, and I want to extract the first part and the
trailing numbers.

OP001 =ABC, 001
ST02 =CD, 02
00A =00A, null

I have the following regular express:
(?<first>.*?)(? <second>\d+)
This one works well for the given first two examples but not the third
one.

And (?<first>.*?)(? <second>\d+)$ returns strange result.
Jul 16 '07 #2
I am using match.Groups.

"Brandon Gano" wrote:
I'm unfamiliar with the <first<secondsy ntax you're using, but the
following regular expression works for the three samples given:

Regex.Replace(" OP001", @"(.*\D+)(\d*)" , @"$1, $2"); // Returns: "OP, 001"
Regex.Replace(" ST02", @"(.*\D+)(\d*)" , @"$1, $2"); // Returns: "CD, 02"
Regex.Replace(" 00A", @"(.*\D+)(\d*)" , @"$1, $2"); // Returns: "00A, "
"Matt" <Ma**@discussio ns.microsoft.co mwrote in message
news:FC******** *************** ***********@mic rosoft.com...
I have the following words, and I want to extract the first part and the
trailing numbers.

OP001 =ABC, 001
ST02 =CD, 02
00A =00A, null

I have the following regular express:
(?<first>.*?)(? <second>\d+)
This one works well for the given first two examples but not the third
one.

And (?<first>.*?)(? <second>\d+)$ returns strange result.

Jul 16 '07 #3
Yes, it works. Thanks.

However, there is another match, for a number

123 =123, null

how to add this one to the regular express?

"Brandon Gano" wrote:
I'm unfamiliar with the <first<secondsy ntax you're using, but the
following regular expression works for the three samples given:

Regex.Replace(" OP001", @"(.*\D+)(\d*)" , @"$1, $2"); // Returns: "OP, 001"
Regex.Replace(" ST02", @"(.*\D+)(\d*)" , @"$1, $2"); // Returns: "CD, 02"
Regex.Replace(" 00A", @"(.*\D+)(\d*)" , @"$1, $2"); // Returns: "00A, "
"Matt" <Ma**@discussio ns.microsoft.co mwrote in message
news:FC******** *************** ***********@mic rosoft.com...
I have the following words, and I want to extract the first part and the
trailing numbers.

OP001 =ABC, 001
ST02 =CD, 02
00A =00A, null

I have the following regular express:
(?<first>.*?)(? <second>\d+)
This one works well for the given first two examples but not the third
one.

And (?<first>.*?)(? <second>\d+)$ returns strange result.

Jul 17 '07 #4
Sorry, should be

123 =null, 123

"Matt" wrote:
Yes, it works. Thanks.

However, there is another match, for a number

123 =123, null

how to add this one to the regular express?

"Brandon Gano" wrote:
I'm unfamiliar with the <first<secondsy ntax you're using, but the
following regular expression works for the three samples given:

Regex.Replace(" OP001", @"(.*\D+)(\d*)" , @"$1, $2"); // Returns: "OP, 001"
Regex.Replace(" ST02", @"(.*\D+)(\d*)" , @"$1, $2"); // Returns: "CD, 02"
Regex.Replace(" 00A", @"(.*\D+)(\d*)" , @"$1, $2"); // Returns: "00A, "
"Matt" <Ma**@discussio ns.microsoft.co mwrote in message
news:FC******** *************** ***********@mic rosoft.com...
>I have the following words, and I want to extract the first part and the
trailing numbers.
>
OP001 =ABC, 001
ST02 =CD, 02
00A =00A, null
>
I have the following regular express:
(?<first>.*?)(? <second>\d+)
This one works well for the given first two examples but not the third
one.
>
And (?<first>.*?)(? <second>\d+)$ returns strange result.
>
Jul 17 '07 #5
Try something like this (not tested):

(.*\D+)?(\d*)
"Matt" <Ma**@discussio ns.microsoft.co mwrote in message
news:AB******** *************** ***********@mic rosoft.com...
Sorry, should be

123 =null, 123

"Matt" wrote:
>Yes, it works. Thanks.

However, there is another match, for a number

123 =123, null

how to add this one to the regular express?

"Brandon Gano" wrote:
I'm unfamiliar with the <first<secondsy ntax you're using, but the
following regular expression works for the three samples given:

Regex.Replace(" OP001", @"(.*\D+)(\d*)" , @"$1, $2"); // Returns: "OP,
001"
Regex.Replace(" ST02", @"(.*\D+)(\d*)" , @"$1, $2"); // Returns: "CD, 02"
Regex.Replace(" 00A", @"(.*\D+)(\d*)" , @"$1, $2"); // Returns: "00A, "
"Matt" <Ma**@discussio ns.microsoft.co mwrote in message
news:FC******** *************** ***********@mic rosoft.com...
I have the following words, and I want to extract the first part and
the
trailing numbers.

OP001 =ABC, 001
ST02 =CD, 02
00A =00A, null

I have the following regular express:
(?<first>.*?)(? <second>\d+)
This one works well for the given first two examples but not the
third
one.

And (?<first>.*?)(? <second>\d+)$ returns strange result.
Jul 17 '07 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
1895
by: Jack Smith | last post by:
I posted this question earlier, but I got no responses. Can anyone help me out here...any hints or even how to start? Thanks in advance. Let doubleswap(x) be the string formed by replacing each a in x by the substring bb and each b by the substring aa. For example, doubleswap(abcab)=bbaacbbaa. Furthermore, let doubleswap(L) be the...
1
4157
by: Kenneth McDonald | last post by:
I'm working on the 0.8 release of my 'rex' module, and would appreciate feedback, suggestions, and criticism as I work towards finalizing the API and feature sets. rex is a module intended to make regular expressions easier to create and use (and in my experience as a regular expression user, it makes them MUCH easier to create and use.) ...
0
1402
by: Glenn Kidd | last post by:
I am trying express a regular expresion used for substitution that is causing me problems and I was hoping that someone might be able to help me. The first part of the regular expression is easy, specifically to match "$!?*", but I do not want to match this if it is prefixed with the regular expression "Foo\.bar\(\s*". Also, on the matches I...
4
5123
by: Buddy | last post by:
Can someone please show me how to create a regular expression to do the following My text is set to MyColumn{1, 100} Test I want a regular expression that sets the text to the following testMyColumn{1, 100}Test Basically I want the regular expression to add the word test infront of the
4
3213
by: Neri | last post by:
Some document processing program I write has to deal with documents that have headers and footers that are unnecessary for the main processing part. Therefore, I'm using a regular expression to go over each document, find out if it contains a header and/or a footer and extract only the main content part. The headers and the footers have no...
6
2283
by: Ludwig | last post by:
Hi, i'm using the regular expression \b\w to find the beginning of a word, in my C# application. If the word is 'public', for example, it works. However, if the word is '<public', it does not work: it seems that < is not a valid character, so the beginning of the word starts at theletter 'p' instead of '<'. Because I'm not an expert in...
3
2533
by: Chris | last post by:
Hi everyone, I'm trying to parse through the contents of some text files with regular expressions, but am new to regular expressions and how to use them in VB.net. I'm pretty sure that the regular expressions are correct as I got them from regexlib.com and tested them in the Regulator and Expresso. The problem is I tested this function...
2
5322
by: Peter | last post by:
Hello, I can't find a real concrete answer to the question, "What is the different between Visual Basic 2005 and Visual Basic 2005 Express?". In other words, what has been removed from VB to turn it into Express, and what functionality is it missing that it can be made available for free?
2
1702
by: shaoen01 | last post by:
Hi, I am new to Perl and stumbled onto some regular expressions and not sure if i am right in interpreting it. If my text is "My organization is great!" Regular express used: s/z*/s/ Returned value will be --> My organisation is great!
0
7695
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, 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...
0
7612
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...
0
7922
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, 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. ...
1
7668
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...
0
3653
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...
0
3637
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2111
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
1
1209
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
936
bsmnconsultancy
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...

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.