ruds <(E-Mail Removed)> writes:

> I'm using java.util.regex for finding exponential numbers from a file.

> the expression I'm using is:

> Pattern p2 = Pattern.compile("[0-9]*\\.[0-9]*[E]\\+[0-9]*");
This matches a sequence of:

zero or more digits

a decimal point

zero or more digits

an "E" (capital)

a "+"

zero or more digits.

I.e., it matches ".E+" as well as "0.0E+0", or any amount of digits

where the zeros are.

It cannot omit any of "." or "E+", so it doesn't match "0", "0.0",

"1E+4" or similar traditional decimal value representations.

> I'm not able to get the result.
Which result. You have not explained what the exact result you want

is, nor how it fails.

I.e., which texts does it accept that it shouldn't, or which texts

does it fail to accept that it should?

> Please tell where I'm going wrong.
When working with regular expressions, always first describe what

strings you want to match, in plain language. Or use syntax diagrams

or BNF grammars or another formal notation, but formalize what you

want, because regular expressions are a pain to write, and when they

get complex, they are pretty much impossible to read.

I'm *guessing* that you want to match all valid Java floating point

literals in exponential form.

I.e. a sequence of

zero or more digits \

an optional decimal point |- i.e. one or more digits with an optional

one or more digits / decimal point somewhere before the end

an "e" or "E"

an optional "+" or "-"

one or more digits.

That regexp could be

"\\d*\\.?\\d+[eE][\\-+]?\\d+"

(In regexps, \d is the same as [0-9])

Try it out, and if it doesn't give what you want, tell us what that is

/L

--

Lasse Reichstein Nielsen -

http://www.velocityreviews.com/forums/(E-Mail Removed)
DHTML Death Colors: <URL:http://www.infimum.dk/HTML/rasterTriangleDOM.html>

'Faith without judgement merely degrades the spirit divine.'