• Post Reply Bookmark Topic Watch Topic
  • New Topic

Understanding Why Regexp is Throwing Runtime Error  RSS feed

 
Steve Dyke
Ranch Hand
Posts: 1783
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have a global variable assigned to filter a string:



When used it throws this runtime error:

SystemOut     O CSSFreeHandNameplateData: updatefreehandnameplatedata: java.util.regex.PatternSyntaxException: Illegal character range near index 13
[^a-zA-Z0-9,-+_*!:;@$.()/ ]
                    ^
 
Steve Dyke
Ranch Hand
Posts: 1783
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Pointer should be just under the '+' character.
 
Henry Wong
author
Sheriff
Posts: 23295
125
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

The comma has an ASCII code of 44. The plus sign has an ASCII code of 43. So, a range from the comma to the plus sign doesn't make sense.

Anyway, I am going to assume that you don't want a range? And that you want the minus sign as one of the possible characters to match? If so, then move the minus sign to the last position of the character class.

Henry
 
Steve Dyke
Ranch Hand
Posts: 1783
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Henry Wong wrote:
The comma has an ASCII code of 44. The plus sign has an ASCII code of 43. So, a range from the comma to the plus sign doesn't make sense.

Anyway, I am going to assume that you don't want a range? And that you want the minus sign as one of the possible characters to match? If so, then move the minus sign to the last position of the character class.

Henry


So like this?

 
Henry Wong
author
Sheriff
Posts: 23295
125
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Steve Dyke wrote:
So like this?


Well, that depends. Do you want the range from the plus sign to the underscore? Or is the minus sign just another character?

If you want the range, then yes, that is correct. If you want the minus sign as just another character, then no, that is not correct. For the minus sign, you need to have it in the last position.

Henry
 
Steve Dyke
Ranch Hand
Posts: 1783
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Henry Wong wrote:
Steve Dyke wrote:
So like this?


Well, that depends. Do you want the range from the plus sign to the underscore? Or is the minus sign just another character?

If you want the range, then yes, that is correct. If you want the minus sign as just another character, then no, that is not correct. For the minus sign, you need to have it in the last position.

Henry


Yes, it is a character I want to match against.

Thank You.
 
Rob Spoor
Sheriff
Posts: 21133
87
Chrome Eclipse IDE Java Windows
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Then you have three choices:
1) put it just after the ^
2) put it just before the closing ]
3) escape it with \
 
Consider Paul's rocket mass heater.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!