473,395 Members | 2,436 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.

Java RegEx pattern

m6s
55
Let's suppose we have, this in an XML
<cs:CUSTOMER_ID><cs:CUSTOMER_ID/>

and a pattern to match : ":CUSTOMER_ID>([A-Za-z][A-Za-z0-9]*|)"

Really, I understand that between the second [] looks for alpharethmetic.
But I don't understand the first [] and after the OR operator '|'.
Has anyone any experience to decipher it?

Thank you in advance
Sep 29 '08 #1
4 4755
JosAH
11,448 Expert 8TB
Let's suppose we have, this in an XML
<cs:CUSTOMER_ID><cs:CUSTOMER_ID/>

and a pattern to match : ":CUSTOMER_ID>([A-Za-z][A-Za-z0-9]*|)"

Really, I understand that between the second [] looks for alpharethmetic.
But I don't understand the first [] and after the OR operator '|'.
Has anyone any experience to decipher it?

Thank you in advance
This part: [A-Za-z][A-Za-z0-9]* reads: one letter [A-Za-z] followed by zero or more
letters or digits [A-Za-z0-9]*.

The vertical bar | at the end is a syntax error and shouldn't be there. The | operator
is a choice A|B meaning either A or B for whatever A or B.

kind regards,

Jos
Sep 29 '08 #2
m6s
55
This part: [A-Za-z][A-Za-z0-9]* reads: one letter [A-Za-z] followed by zero or more
letters or digits [A-Za-z0-9]*.

The vertical bar | at the end is a syntax error and shouldn't be there. The | operator
is a choice A|B meaning either A or B for whatever A or B.

kind regards,

Jos
Could n't just say then [A-Za-z0-9]? ? So the english questionmark to say one or more?
I bet the | is the or for nothing, so to say bring me one ore more, or nothing.. I think..
Sep 29 '08 #3
Ganon11
3,652 Expert 2GB
[a-zA-Z0-9]* is very different from [a-zA-Z][a-zA-Z0-9]*. This first will match 123cat, and the second will not. Both, however, will match cat123.

The first, [a-zA-Z0-9]*, looks for any sequence of digits and letters. They can be in any order and are under no constraints.

The second, [a-zA-Z][a-zA-Z0-9]*, MUST match a letter first, and only then will match any sequence of letters or digits. So it can't match something starting with a number, which the first regex can.

Some word starting with a letter, but made of of digits and letters...sound like anything to you?
Sep 29 '08 #4
m6s
55
[a-zA-Z0-9]* is very different from [a-zA-Z][a-zA-Z0-9]*. This first will match 123cat, and the second will not. Both, however, will match cat123.

The first, [a-zA-Z0-9]*, looks for any sequence of digits and letters. They can be in any order and are under no constraints.

The second, [a-zA-Z][a-zA-Z0-9]*, MUST match a letter first, and only then will match any sequence of letters or digits. So it can't match something starting with a number, which the first regex can.

Some word starting with a letter, but made of of digits and letters...sound like anything to you?
It seems rather clear now, perhaps, however if we need the first word after the '>' whether name or number this trick is too restrictive I think. We could have loosen it a bit.....
I tried to some regexp utility or grep itself, but couln't get what the writer wanted to say...
In any case thank you very much... It was very detailed description.
Sep 29 '08 #5

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

Similar topics

1
by: Ye Zhou | last post by:
Hi all, I am trying to convert a perl program into java and I got stuck in the regular expression part. It seems like java.util.regex couldn't help much. I checked with Apache regexp and didn't...
1
by: pawel | last post by:
I have made some comparision C# to Java RegularExpression. The problem was to find out if the rule match some text. Matching were done for precompiled regular expressions, in 100000 iterations...
4
by: aevans1108 | last post by:
expanding this message to microsoft.public.dotnet.xml Greetings Please direct me to the right group if this is an inappropriate place to post this question. Thanks. I want to format a...
9
by: Whitless | last post by:
Okay I am ready to pull what little hair I have left out. I pass the function below my String to search, my find string (a regular expression) and my replace string (another regular expression)....
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...
3
by: gimme_this_gimme_that | last post by:
I'm driving Windows XP and could use a tip on installing a function written in Java. 1. I created the a Java jar file, named UdfUtils.jar, from the Java source file shown below: 2. I copied the...
8
by: gimme_this_gimme_that | last post by:
I have the following Java code : package com.rhi.bb.udf.utils; import java.sql.Clob; import java.sql.SQLException; import java.util.regex.Pattern; import java.util.regex.Matcher;
8
by: sherifffruitfly | last post by:
Hi, I've been searching as best I can for this - coming up with little. I have a file that is full of lines fitting this pattern: (?<year>\d{4}),(?<amount>\d{6,7}) I'm likely to get a...
0
by: vmysore | last post by:
I am trying to get all the columns selected within a SQL query (including the sub selects). When the code hits matcher.find(). i get the following exception: Exception in thread "main"...
4
by: sukatoa | last post by:
This was my first time to encouter this kind of exception.... that exception appears when i invoked the the method below. private final String encrypting(String enc){ int...
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
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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
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,...

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.