If you use quotes, you're asking for a regular expression split.
| is the "or" character, so your regex matches nothing or nothing. So everything is split.
If you use
split("""\|""") you should get what you want.
Split takes a regex as first argument, so your call is interpreted as "empty string or empty string". To get the expected behavior you need to escape the pipe character "\\|".
| is a special regular expression character which is used as a logical operator for
Since java.lang.String#split(String regex); takes in a regular expression, you're splitting the string with "none OR none", which is a whole another speciality about regular expression splitting, where none essentially means "between every single character".
To get what you want, you need to escape your regex pattern properly. To escape the pattern, you need to prepend the character with
\ and since
\ is a special
String character (think
\r for example), you need to actually double escape so that you'll end up with
For full Java regular expression syntax, see java.util.regex.Pattern javadoc.
- why split does not work in yield comprehension scala
- Why does pattern matching in Scala not work with variables?
- Eclipse, Android, Scala made easy but still does not work
- scala string.split does not work
- Scala String toInt - Int does not take parameters
- IntelliJ IDEA Hotkey for comment does not work with Scala
- 7.toBinayString does not work in scala REPL, but with val k=7 it works
- Command `timeout` does not work with Scala - why?
- Scala REPL does not work on Ubuntu
- Scala sbt assembly jar does not work (class implementation not found) but code works when through IntelliJ
- scala project does not work in intellij
- Scala Stdin.readLine() does not seem to work as expected
- Why the scala :_* to expand a Seq into variable-length argument list does not work in this case?
- string interpolation does not work in function definition
- Why does the same scala code work OK in command line while not in Intellij?
- Why does Scala implicit conversion work here with two args but not with one?
- Simple file read with Scala does not work
- Why does $ not work with values of type String (and only with the string literals directly)?
- Equality of Scala case class does not work in junit assertEquals when it contains an inner Array
- HBase Scan TimeRange Does not Work in Scala
- Why does this Scala placeholder not work
- Build.scala: specify scala version does not work
- JsonProperty annotation does not work for Json parsing in Scala (Jackson/Jerkson)
- Scala - implicit method parameter does not work
- scala call shell command "rm -rf *" does not work
- Why does Regex pattern matching not work sometimes in Scala
- Why does Scala reify not work as according to the docs?
- Implicit Java to Scala collection conversion does not work
- scala sortBy using _ placeholder parameter does not work
- Why does string interpolation not work in this case?
More Query from same tag
- Kryo: How to use the CollectionSerializer with Scala?
- IntelliJ No Source to compile with Maven Error
- Work on list of tuples in Scala - part 3
- How to convert an imperative double for-loop to functional style without return in Scala?
- How to compare to strings after converting them to a double?
- Scala - ambiguous reference to overloaded definition -- with varargs
- Intersection type with type definition
- How to avoid http code 204?
- How to copy a single value in a dataframe to another dataframe in spark scala
- How to use the Akka ask pattern without blocking
- Composition of PartialFunctions in Scala
- Scala <collection>.reduce strange behaviour on generic types
- com.databricks.spark.csv version requirement
- Polymorphic updates in an immutable class hierarchy
- Save file names from S3 location in an array
- Implicit conversion between java and scala collections using JavaConversions
- Spark: Calculate event end time on 30-minute intervals based on start time and duration values in previous rows
- How to convert a Dataframe into a List (Scala)?
- Play with Reactive Slick with jdbc asyn or jdbc (blocking by default)?
- Pattern match against List 'init' and 'last' instead of 'head' and 'tail'
- Why does IDEA 14 report "Cannot load facet "Scala": Unknown type of facet "scala""?
- reference to overloaded methods in scala
- A/B test clients from controller
- Scala collections: Why is Elem contravariant in Builder but covariant in TraversableLike?
- Editing Combobox Scala
- Get the text only part of an xml node
- Using ScalaTest to test java that contain @Autowired and private fields
- Compare nested lists using scala test
- Sorted table with a map in Apache Ignite
- Automatic null assert in scala