473,395 Members | 2,006 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,395 software developers and data experts.

Regular expression issue

Hi,

I am trying to extract some letters from a piece of string, but I do
not know how many letters I need to extract.

All I know is that there are letters that follow the letter:

Example:

At the moment I am using the following regualr expression:

(XX|YY)(\w\w)(\d{1,15})

Two example strings are:

EXAMPLE 1 - XXAB123456789
EXAMPLE 2 - YYABC123456789

I know I can get the XX or YY

However in both example strings I need to get AB or ABC.

However my regular expression (XX|YY)(\w\w)(\d{1,15}) will only get AB
in EXAMPLE 1 which is correct
but it will only get AB in EXAMPLE 2 and not ABC.

If I use (XX|YY)(\w\w\w)(\d{1,15}) it will get AB1 in EXAMPLE 1 rather
than AB.

Can anyone help me?

Regards
Simon

Jan 19 '07 #1
2 995
Rik
si********@hotmail.com wrote:
Hi,

I am trying to extract some letters from a piece of string, but I do
not know how many letters I need to extract.

All I know is that there are letters that follow the letter:

Example:

At the moment I am using the following regualr expression:

(XX|YY)(\w\w)(\d{1,15})

Two example strings are:

EXAMPLE 1 - XXAB123456789
EXAMPLE 2 - YYABC123456789

I know I can get the XX or YY

However in both example strings I need to get AB or ABC.

However my regular expression (XX|YY)(\w\w)(\d{1,15}) will only get AB
in EXAMPLE 1 which is correct
but it will only get AB in EXAMPLE 2 and not ABC.

If I use (XX|YY)(\w\w\w)(\d{1,15}) it will get AB1 in EXAMPLE 1 rather
than AB.

(XX|YY)([a-zA-z]+)([0-9]{1,15})
--
Rik Wasmus
Jan 19 '07 #2

si********@hotmail.com wrote:
Hi,

I am trying to extract some letters from a piece of string, but I do
not know how many letters I need to extract.

All I know is that there are letters that follow the letter:

Example:

At the moment I am using the following regualr expression:

(XX|YY)(\w\w)(\d{1,15})

Two example strings are:

EXAMPLE 1 - XXAB123456789
EXAMPLE 2 - YYABC123456789

I know I can get the XX or YY

However in both example strings I need to get AB or ABC.

However my regular expression (XX|YY)(\w\w)(\d{1,15}) will only get AB
in EXAMPLE 1 which is correct
but it will only get AB in EXAMPLE 2 and not ABC.

If I use (XX|YY)(\w\w\w)(\d{1,15}) it will get AB1 in EXAMPLE 1 rather
than AB.

Can anyone help me?

Regards
Simon
Hi

Look at character ranges - e.g. /[A-Z]/

Thus

(XX|YY)([A-Z]+)(\d{1,15})

or

(XX|YY)([A-Z]{1,3})(\d{1,15})

Regards

Julian Turner

Jan 19 '07 #3

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

Similar topics

3
by: Lisa Bogart | last post by:
I am trying to take a string and parse it out into multiple strings based on a pattern but am stuck and am hoping someone can give me a clue. My pattern looks like so: sMatch =...
3
by: James D. Marshall | last post by:
The issue at hand, I believe is my comprehension of using regular expression, specially to assist in replacing the expression with other text. using regular expression (\s*) my understanding is...
7
by: Billa | last post by:
Hi, I am replaceing a big string using different regular expressions (see some example at the end of the message). The problem is whenever I apply a "replace" it makes a new copy of string and I...
9
by: Pete Davis | last post by:
I'm using regular expressions to extract some data and some links from some web pages. I download the page and then I want to get a list of certain links. For building regular expressions, I use...
25
by: Mike | last post by:
I have a regular expression (^(.+)(?=\s*).*\1 ) that results in matches. I would like to get what the actual regular expression is. In other words, when I apply ^(.+)(?=\s*).*\1 to " HEART...
6
by: deepak_kamath_n | last post by:
Hello, I am relatively new to the world of regex and require some help in forming a regular expression to achieve the following: I have an input stream similar to: Slot: slot1 Description:...
2
by: Prakash | last post by:
Dear Friends, In my web application i have two textboxes to collect "ORIGIN" and "DESTINATION" stations. These stations are represented as three letter code.. We have an option like to provide...
8
by: sri_san | last post by:
Hello, I am trying to write a regular expresssion which validates against the URL and the textfield has 'http://' prefilled. I either want a valid URL or just leave the 'http://' as it is. I...
12
by: =?Utf-8?B?SlA=?= | last post by:
I am a newbie to regular expressions and want to extract a number from the end of a string. The string would have these formats: image/4567 image/45678 image/456789 I would also want to...
18
by: Lit | last post by:
Hi, I am looking for a Regular expression for a password for my RegExp ValidationControl Requirements are, At least 8 characters long. At least one digit At least one upper case character
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
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.