Regex:Split Problem - Must be coding it Wrong !

rfhall50

Member
Licensed User
Longtime User
I must be coding my Regex:Split incorrectly. It appears to be failing on the Regex line. Code is listed below, followed by output from Log. I am getting my Log entry (hightlighted in Blue) showing the input value, but it never gets past the Regex line.

Would appreciate any help you all can give . Thank You.

Bob

B4X:
Sub Activity_Create(FirstTime As Boolean)
[INDENTDim InputData() As String][/INDENT]   
   Dim RawData As String
   RawData = "Ficticious Name++Dummy Department++++++"
   Log ("RawData: " & RawData)
   InputData = Regex.Split("+", RawData)
   Log ("InputData(1): " & InputData(1))
   Log ("InputData(2): " & InputData(2))   
End Sub

B4X:
** Activity (main) Create, isFirst = true **


[COLOR="Blue"]RawData: Ficticious Name++Dummy Department++++++[/COLOR]


main_activity_create (java line: 251)





java.util.regex.PatternSyntaxException: Syntax error U_REGEX_RULE_SYNTAX near index 1:
+
 ^
   at com.ibm.icu4jni.regex.NativeRegEx.open(Native Method)
   at java.util.regex.Pattern.compileImpl(Pattern.java:383)
   at java.util.regex.Pattern.<init>(Pattern.java:341)
   at java.util.regex.Pattern.compile(Pattern.java:317)
   at anywheresoftware.b4a.keywords.Regex.getPattern(Regex.java:34)
   at anywheresoftware.b4a.keywords.Regex.Split2(Regex.java:75)
   at anywheresoftware.b4a.keywords.Regex.Split(Regex.java:69)
   at PCAW.Residents.main._activity_create(main.java:251)
   at java.lang.reflect.Method.invokeNative(Native Method)
   at java.lang.reflect.Method.invoke(Method.java:521)
   at anywheresoftware.b4a.BA.raiseEvent2(BA.java:104)
   at PCAW.Residents.main.afterFirstLayout(main.java:84)
   at PCAW.Residents.main.access$100(main.java:16)
   at PCAW.Residents.main$WaitForLayout.run(main.java:72)
   at android.os.Handler.handleCallback(Handler.java:587)
   at android.os.Handler.dispatchMessage(Handler.java:92)
   at android.os.Looper.loop(Looper.java:123)
   at android.app.ActivityThread.main(ActivityThread.java:4627)
   at java.lang.reflect.Method.invokeNative(Native Method)
   at java.lang.reflect.Method.invoke(Method.java:521)
   at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
   at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
   at dalvik.system.NativeStart.main(Native Method)
java.util.regex.PatternSyntaxException: Syntax error U_REGEX_RULE_SYNTAX near index 1:


+
 ^
 

Cableguy

Expert
Licensed User
Longtime User
this may seem a stupid question to you, but have you DIMed the InputData array?, have you tried to split with the normal string object?
 
Upvote 0

kickaha

Well-Known Member
Licensed User
Longtime User
The problem is the "+". It is a special character in Regex, and if you want to match it you need to escape it with a "\" thus:
B4X:
   InputData = Regex.Split("\+", RawData)
 
Upvote 0

rfhall50

Member
Licensed User
Longtime User
Thank you for the responnses. I did DIM it in a global declaration. Cant say as I am surprised about the "special" use of +. Can't wait to get back and try it tomorrow.

Again thank you to both.

Bob
 
Upvote 0

rfhall50

Member
Licensed User
Longtime User
Follow-up: Special Characters

Where can I find a list of special characters and how they are used ?

Thanks...

Bov
 
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…