package: jregex1.2_01
given string: 1234567890123456b
problem: get rid of last non-digit character and
capture 12-digits number counting from the end of
string.
pattern: ^\d{4}|\D*$ (in words, get rid of any 4
digits at the beginning and any non-digit character
at the end of the string)
replace with: (nothing)
result with JRegex: (nothing)
result with Java1.4 util.regex package:
567890123456 (12 digits as expected)
The cause of the problem is that JRegex captures
_every_ 4-digits group in the string 1234, 5678,
9012 and 3456, then it replaces all of them with
nothing. That would be right for \d{4} pattern. But, I
put ^ in front of \d{4} and this means "exactly 4
digits at the beginning of the string".
Please, correct me if I am overlooking anything. Any
help would be greatly appriciated.
Vladimir. vermakov@hotmail.com
Logged In: YES
user_id=367459
Hello, Vladimir!
Yes, that's a mistake in the Replacer implementation.
To be fixed in upcoming version.
Regards,
Sergey
Logged In: YES
user_id=367459
Hello, Vladimir!
Yes, that's a mistake in the Replacer implementation.
To be fixed in upcoming version.
Regards,
Sergey
Logged In: YES
user_id=552909
^ might mean "not" and not "begin line". Is the compilation
flag 'm' set? (like it says on
http://jregex.sourceforge.net/syntax.html\).
I hope this may be usefull to you.
Aureliano.
Logged In: YES
user_id=908396
If you're using Replacer.replace, that replaces ALL
occurrences of the pattern. Depending on how it's
implemented, it might match ^\d{4} over and over, because
after the first 4 digits are removed, another sequence of 4
gets in front. That still sounds like a bug, though.