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

TimeStamp Column Problem...
I'm mad at my self and thinking I'm a little retarded. It just be some one mistake I'm missing here.

Wierd echo error?
Hi, i got the most wierd php error ever and i don't know why..
Code: echo "<t

Mysterious Timeouts
I've deployed a few simple AJAX-enabled web page to a local server that is accessed through the Inte

Table sorting
Hi,

I'm trying to modify the following in order to make the output table sorted alphabeticall

how to use two buttons with php
hi i have one form. there are three fields which are to be filled by the user. and then there are tw

[RESOLVED] Socket/Port remains open after app crashes
I'm having this problem with a networked app in vb.net.

If the program exits normally the por

Production of mango in processing industry
Hi,

We have one scenario ,company is in process industry,they are manufacturing MANGO pul

IS this code correct
The reason i ask is everything underneath it appears to be alink as well, tis blimmin annoying

chat
hello i'm amir i need a chat source code in asp.net 2.0 without Ajax. anybody can help me?

cookie problem
I hv a website url
In this site main menu functionality based on cookie when user click on parti

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