Discussion:
Regx problem
(too old to reply)
unknown
2017-08-27 16:17:11 UTC
Permalink
I have always had a hard time with regx. Even the simple things like
this one. All I want to do is replace a string with another string. In
this case a ' replaced with ''.

I am trying:
rsNname = rsNname.replaceAll("\\d \\D \\W \\w \\S \\s", "''");
rsNname = rsNname.replaceAll("[+.-^]", "''");
rsNname = rsNname.replaceAll("[$&+,:;=?@#|'<>.^*()%!-]", "''");
rsNname = rsNname.replaceAll("['++]", "\\''");

Nomatter what I do I get a compli error "Derefferencing pointer
error". Any one have any suggestions.

I could write code to do the same but seems better to do in one
commane.

Thanks in advance
Eric Sosman
2017-08-27 19:17:01 UTC
Permalink
Post by unknown
I have always had a hard time with regx. Even the simple things like
this one. All I want to do is replace a string with another string. In
this case a ' replaced with ''.
The problem you describe can be solved without using regular
expressions at all:

String original = ...;
String replaced = original.replace("'", "''");
Post by unknown
rsNname = rsNname.replaceAll("\\d \\D \\W \\w \\S \\s", "''");
rsNname = rsNname.replaceAll("[+.-^]", "''");
rsNname = rsNname.replaceAll("['++]", "\\''");
Nomatter what I do I get a compli error "Derefferencing pointer
error". Any one have any suggestions.
No, not without (1) the code you are trying to compile and
(2) the *exact* error message or messages the compiler emits.
Post by unknown
I could write code to do the same but seems better to do in one
commane.
It's not clear to me what "do the same" means. The replaceAll()
calls you show seem to have nothing to do with the problem you say
you are trying to solve -- in fact, some of them are nonsensical to
the point that I think they would throw exceptions at run-time (not
compile-time). If the replace() call above doesn't meet your needs,
please show your actual code and your actual error messages, and
give a fuller description of what you're trying to do.
--
***@comcast-dot-net.invalid
Twelve hundred forty-two days to go.
unknown
2017-08-28 13:13:15 UTC
Permalink
On Sun, 27 Aug 2017 15:17:01 -0400, Eric Sosman
Post by Eric Sosman
Post by unknown
I have always had a hard time with regx. Even the simple things like
this one. All I want to do is replace a string with another string. In
this case a ' replaced with ''.
The problem you describe can be solved without using regular
String original = ...;
String replaced = original.replace("'", "''");
Post by unknown
rsNname = rsNname.replaceAll("\\d \\D \\W \\w \\S \\s", "''");
rsNname = rsNname.replaceAll("[+.-^]", "''");
rsNname = rsNname.replaceAll("['++]", "\\''");
Nomatter what I do I get a compli error "Derefferencing pointer
error". Any one have any suggestions.
No, not without (1) the code you are trying to compile and
(2) the *exact* error message or messages the compiler emits.
Post by unknown
I could write code to do the same but seems better to do in one
commane.
It's not clear to me what "do the same" means. The replaceAll()
calls you show seem to have nothing to do with the problem you say
you are trying to solve -- in fact, some of them are nonsensical to
the point that I think they would throw exceptions at run-time (not
compile-time). If the replace() call above doesn't meet your needs,
please show your actual code and your actual error messages, and
give a fuller description of what you're trying to do.
Thanks so much for your elegant solution...

The code is to large...basically comes down to just the
string.replaceAll() method

Again thanks a lot

I have been away from coding for some years.

unknown
2017-08-27 20:30:18 UTC
Permalink
Post by unknown
I have always had a hard time with regx. Even the simple things like
this one. All I want to do is replace a string with another string. In
this case a ' replaced with ''.
rsNname = rsNname.replaceAll("\\d \\D \\W \\w \\S \\s", "''");
rsNname = rsNname.replaceAll("[+.-^]", "''");
rsNname = rsNname.replaceAll("['++]", "\\''");
Nomatter what I do I get a compli error "Derefferencing pointer
error". Any one have any suggestions.
I could write code to do the same but seems better to do in one
commane.
Thanks in advance
Thanks but I fixed it. What I needed was

rsNname = rsNname.replaceAll("\''","''");
Eric Sosman
2017-08-27 20:53:32 UTC
Permalink
Post by unknown
Post by unknown
I have always had a hard time with regx. Even the simple things like
this one. All I want to do is replace a string with another string. In
this case a ' replaced with ''.
rsNname = rsNname.replaceAll("\\d \\D \\W \\w \\S \\s", "''");
rsNname = rsNname.replaceAll("[+.-^]", "''");
rsNname = rsNname.replaceAll("['++]", "\\''");
Nomatter what I do I get a compli error "Derefferencing pointer
error". Any one have any suggestions.
I could write code to do the same but seems better to do in one
commane.
Thanks in advance
Thanks but I fixed it. What I needed was
rsNname = rsNname.replaceAll("\''","''");
This "replacement" is a no-op; it accomplishes nothing.
I'll repeat my earlier suggestion: Show us your code, and give
a careful description of what you're trying to do.
--
***@comcast-dot-net.invalid
Twelve hundred forty-two days to go.
Loading...