473,473 Members | 2,050 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

How to write the following regular express?

123ABC123 =123ABC, 123
343BBB =343BBB, null
12323 =null, 12322

(?<first>.*\D+)(?<second>\d*) doesn't work on the third line.

Jul 17 '07 #1
1 1234
ni******@gmail.com wrote:
123ABC123 =123ABC, 123
343BBB =343BBB, null
12323 =null, 12322

(?<first>.*\D+)(?<second>\d*) doesn't work on the third line.
Try:

var data = {
x : '123ABC456',
y : '343BBB',
z : '12345'
};

var p, t, u,
re = /(^\d+[^\d]+|^.*?)(\d*$)/g;

for (p in data) {
u = [];
while (t = re.exec(data[p])) {
u[0] = t[1] || null;
u[1] = t[2] || null;
}
alert('String: ' + data[p] + '\n\n' + u.join(' : '));
}
You could also use:

re = /(^\d+[^\d]+|^)(\d*$)/g;
or if ^\d doesn't suit (it will match any non-digit):

re = /(^\d+[A-Z]+|^)(\d*$)/g;
or

re = /(^\d+[a-z]+|^)(\d*$)/ig;
may be safer - take your pick. Tested in Safari, Firefox and Opera.

--
Rob
"We shall not cease from exploration, and the end of all our
exploring will be to arrive where we started and know the
place for the first time." -- T. S. Eliot
Jul 17 '07 #2

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

Similar topics

4
by: matt cook | last post by:
The concept - a HTML file changes regularly. However, only certain parts of the page change. I want to find a regular expression that describes that changed area. Can anyone here think of a...
2
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...
4
by: Bill Cohagan | last post by:
I'm writing a console app in c# and am encountering a strange problem. I'm trying to use redirection of the standard input stream to read input from a (xml) file. The following code snippet is from...
0
by: Welman Jordan | last post by:
Hello, I would like to write a simple forum for my site, which enables some formating, like , , and some other BBS format code. For example, the user inputs this string in a multiline...
1
by: Mamatha | last post by:
Hi I want to write regular expression for odds which related to sports in VB.NET. But i don't know how to write regular expression for odds. If anyone knows the solution or any related urls...
3
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...
4
by: Chris | last post by:
I want to ensure a password has a least one lower case letter, one upper letter and a number. I'm a bit of a newbie but I understand you can use the pipe system for OR what about AND.I would like...
8
by: Mohammad Omer | last post by:
Hi, i want to use regular expression in my project for validation of email. How i can use Regular Expression in VC?? i am using vs2k5 IDE. i seen boost api for regular expression, is it any...
47
by: Henning_Thornblad | last post by:
What can be the cause of the large difference between re.search and grep? This script takes about 5 min to run on my computer: #!/usr/bin/env python import re row="" for a in range(156000):...
2
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/ ...
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...
1
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...
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...
0
agi2029
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,...
1
isladogs
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...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
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...
0
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 ...

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.