• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Jeanne Boyarsky
  • Devaka Cooray
  • Paul Clapham
Sheriffs:
  • Tim Cooke
  • Knute Snortum
  • Bear Bibeault
Saloon Keepers:
  • Ron McLeod
  • Tim Moores
  • Stephan van Hulst
  • Piet Souris
  • Ganesh Patekar
Bartenders:
  • Frits Walraven
  • Carey Brown
  • Tim Holloway

How to use Delimter

 
Ranch Hand
Posts: 162
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I want to split a string using " ( " as a delimiter.

My code for that is :


but its throwing error as "Exception in thread "main" java.util.regex.PatternSyntaxException: Unmatched closing ')'
)"


How to mention a backet as a delimiter??

Thank you
 
Java Cowboy
Posts: 16084
88
Android Scala IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The argument that you pass to the split method is a regular expression, and ( has a special meaning in regular expressions. You need to escape it:
 
Neeba Rebbaca
Ranch Hand
Posts: 162
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Jesper Young wrote:The argument that you pass to the split method is a regular expression, and ( has a special meaning in regular expressions. You need to escape it:




Thank You.

Suppose if i have more than one delimiter how can i split it at a time??

Is there any way for it or i have to split it sperately???
 
Jesper de Jong
Java Cowboy
Posts: 16084
88
Android Scala IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Neeba Rebbaca wrote:Suppose if i have more than one delimiter how can i split it at a time??


Write a regular expression that matches all the characters or character sequences that you want to be recognised as delimiters.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!