Search...
FAQs
Subscribe
Pie
FAQs
Recent topics
Flagged topics
Hot topics
Best topics
Search...
Search within Beginning Java
Search Coderanch
Advance search
Google search
Register / Login
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
Pie Elite
all forums
this forum made possible by our volunteer staff, including ...
Marshals:
Campbell Ritchie
Jeanne Boyarsky
Ron McLeod
Paul Clapham
Liutauras Vilda
Sheriffs:
paul wheaton
Rob Spoor
Devaka Cooray
Saloon Keepers:
Stephan van Hulst
Tim Holloway
Carey Brown
Frits Walraven
Tim Moores
Bartenders:
Mikalai Zaikin
Forum:
Beginning Java
Regular Expression
Ajay Divakaran
Greenhorn
Posts: 22
posted 16 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
String
s="|-|-|";
Using
Pattern
and Matcher in java.util.regex.* how do i write a RE
to match one or more occurance of "|-|"
Adam Nace
Ranch Hand
Posts: 117
posted 16 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
What you have to watch out for is that the | has a special meaning in a regex, so you need to escape it. Furthermore, the \ has a special meaning in
java
, so you have to escape it. So what
you should
get is this:
import java.util.regex.*; public class Test { public static void main(String [] args) { Pattern pattern = Pattern.compile("\\|(-\\|)+"); String sample = "|-|-|"; Matcher matcher = pattern.matcher(sample); System.out.println(matcher.matches()); } }
Consider Paul's
rocket mass heater
.
reply
reply
Bookmark Topic
Watch Topic
New Topic
Boost this thread!
Similar Threads
How to use OR in Regular Expressions?
is there anything like isNum() ?
The meaning of () in the following SCJP test Objective
JDK 1.4 Regular expressions
string search
More...