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.
Did you know?Explore Trending and Topic pages for more stories like this.
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
Warning: mysql_num_rows() supplied argument is not a valid MySQL result resource
This may be simple I just may need another pair of eyes..
When i get records back the below c
PHP & Java
Hello,
can PHP code be used inside java code?
Code: <SCRIPT LANGUAGE="Java
Remove values in array2 from array1
I have two arrays.
Array 1 is where the array key holds various different numbers. For exampl
multipart emiail forms
Hi All,
I am new to the boards and I've been working on a form (which is rather massive, imo
Google Wave
So... has anyone used it yet? Is it any good?
http://wave.google.com/help/wave/about.html#vid
About imagecopyresampled()
Hello,
I am looking to use this function to resize parts of an image to a fixed thumbnail siz
javascript in php code causes page to display white
Hi All,
Odd one this, I've got the following code (below) which is a simple log in form. The
Help with file_get_html
The following code gives the expected results:
<html>
<head&g
update sql when refresh - php
hi
I have made a table (attachement)
the users can update the sql database using + or x bu
DateObject and Nulls
Hi all,
I have an array mapped to a value object. One of the items in the array is a PHP Date