java


Parsing a string works not as expected [duplicate]


This question already has an answer here:
Splitting a Java String by the pipe symbol using split(“|”)
6 answers
There is a string which I trying to parse by "|" symbol:
1-20|21-40|41-60|61-80|81-100|101-120|121-131
String[] arr = text.split("|");
for(int i = 0; i <arr.length; i++){
System.out.println( arr[i] );
}
It parses to every character, like
1
-
2
0
|
2
1
...
How to parse the source string for elements like:
1-20
| is a special character in Java's regex syntax that means a logical "or" between two matching groups. If you want to match the | literal, you need to escape it:
String[] arr = text.split("\\|");
This | is a special character in regular expression(s), you need to escape it. Like,
String[] arr = text.split("\\|");
| is a metacaracter in regex. Escape it:
String[] splitValues = text.split("\\|");
| is a special character in regular expression, so, use \ to escape that,
String[] arr = text.split("\\|");
escape the pipe using "\\|"
String[] arr = text.split("\\|");

Related Links

RabbitMQ: publish in node.js subscribe in Java
Cleanly stop a running JRuby scriptlet
How can i write more than 1 database Table into one .csv file using open CSV?
PF datatable value and filteredValue - best practise
Delete [Reverse Backspace] Button
ManyToMany collection keeps getting deleted
Run unit tests only on Windows
Session ID failing when screen duplicated
Android Bluetooth connection polar - keep sending data after removing chest belt
Maximize not working in different resolutions in JFrame with JTattoo
Illegal character in query at index , while inserting double quotes in a url
Getting NullPointerException while parsing JSONArray
Memory leakage in Java
Iterator on Mapwritable of MapWritable
Add HTTPS to a custom domain on Google App Engine (and keep HTTP working)
linkgrammar java API unfound

Categories

HOME
c#-4.0
include
yahoo-oauth
retrofit
installshield
android-youtube-api
maude-system
kibana-4
windows-10-universal
floating-action-button
modelica
gz
ibm-odm
flask-wtforms
windows-server-2012
vaadin7
opentracing
pc
windows-7-x64
serilog
propel
connection-string
oracle-coherence
text-rendering
excel-vba-mac
nhibernate-envers
arabic
captiveportal
crystal-reports-2010
wpfdatagrid
newline
microsoft-chart-controls
bcd
phonegap
exuberant-ctags
oracle-fusion-middleware
copying
usbserial
subset-sum
mozilla
mmenu
host
devextreme
dynamics-crm-2013
service-discovery
lumberjack
reportingservices-2005
botbuilder
menuitem
youcompleteme
chain-builder
veracode
magma
nodebb
snmptrapd
knpmenubundle
vtigercrm
word-vba-mac
removechild
dstu2-fhir
measures
websitepanel
lttng
ready-api
yaws
vhd
separator
lemon
wordml
computer-algebra-systems
muse
drawbitmap
processmodel
generic-programming
p2
gadt
gui-test-framework
mdt
internet-connection
fluentautomation
picturefill
bundles
datagridviewcolumn
gnu-smalltalk
geos
jsctypes
ruby-datamapper
dataservice
django-nonrel
chronoforms
spring-validator
lcs
browser-detection
javaspaces
ticoredatasync
semantic-diff
data-loss
mod-auth
subgurim-maps
joyent
psi
xmlspy
appendto
nhibernate.search
nsviewanimation
perfect-hash
mediarss

Resources

Encrypt Message



code
soft
python
ios
c
html
jquery
cloud
mobile