Regular expression tips or resources
Posted on
16th Feb 2014 07:03 pm by
admin
Hello! I'm having some issues implementing the appropriate regex patter to eliminate unwanted characters from a string.
Here is a sample string:
Code: String str = "test-hello. me please3, _dog[ -()"; What I need to do is create a regex that will take out all non word characters except for spaces AND strings of type "test-hello" - in other words any string that has word or digit characters followed by a "-" (hyphen) followed by more word or digit characters - this is what is giving me trouble.
What I have right now which is perfect except for the "test-hello" type strings is:
Code: Pattern replace = Pattern.compile("([^\w ])");Matcher matcher = replace.matcher(str);str = matcher.replaceAll(""); The above code removes all non word or digit characters except for spaces but it will obviously still remove the "-" in "test-hello".
I'm not looking for the whole answer of course but any tips or resources I can be pointed to would be greatly appreciated. I'm not familiar with the regex syntax in Java as I am in say PHP.
Thank you!
No comments posted yet
Your Answer:
Login to answer
84
39
Other forums
SQL Query/echo not working
Hey all,
I'm trying to run (what I thought) was a simple operation and it isn't working. I h
Why use OOP?
Can someone explain to me why I should use OOP instead of procedure based code.
Im building a
Java API in PHP?
I have an application that we use internally here at the office.
The software company provide
Login Control?!
I have a Web Site that uses the login control also I have set the destinationurl to the page I want
Auto install
Hi I have a directory lets say "apps" that I then have more folders ie "email",
Where is my php.ini???
Hi
First off - apologies - i'm not a coder so this may sound very amateur.
I'm having
Header is not working in IE
Hi ! header function is not working in IE but it works in FF, Safari, Chrome. any help please. :
Update Myspace status with CURL
Logging in:
Code: <?php
class Myspace
{
function login($username, $pa
Export hangs
Hi all, please help
I have a Oracle 10.2.0.3.0 database. When I want to query the dba_segmen
Posting to another Site?
I have software that people install.
When they install it, is there a way to make it post their d