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 Like 39 Dislike
Previous forums Next forums
Other forums

Mysql query, two times?
Hello to all,

I'm new to php coding and i like it alot. I need help with some noob stuff.

Multiple submit forms inside a mysql array page
Hi all,

Im having trouble to get the beneath script to work the thing i can't seem to get wor

Include a php
Hello,

I'm trying to include a function that shows the recent searches.
Example I have <

how to put the 0-100 numbers into 1.txt and 100-200 into 2.txt ?
how to put the 0-100 numbers into 1.txt and 100-200 into 2.txt and so on 200-300 into file 3.txt ?

building a function with multiple outputs
I want to build a function that has multiple outputs.

I know but am not to sure how I should

drop-down with sub-category appear
Hello,

i know how to build a simple dro-down list, im looking for a code when im gonna choose

if description does not contain the following words
Hello everyone,

I am parsing a MS Excel (.xls) file and adding it's content to a mySQL databa

post to self
Trying to get my form to submit to itself. However I am also trying to use an image for my submit bu

mail()
Hi all. I have a problem with emails. I am trying to set up a mail system where customers can subscr

File upload issues
Hi Guys,

Can anyone see any issues with this code:
Code: $setImage= 'productimages/' . dat

Sign up to write
Sign up now if you have flare of writing..
Login   |   Register
Follow Us
Indyaspeak @ Facebook Indyaspeak @ Twitter Indyaspeak @ Pinterest RSS



Play Free Quiz and Win Cash