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

php problem?
I don't think I'm stupid, but maybe I am.

I am working on a sit for a friend I am try to put

Preg_match with an array
is there an away to use preg_match with an array?

i want to check a string with an array to s

switch not getting value
what am i doing wrong?
i want to populate the country list according to the category
i want to

remove a ; from emails in textarea
Code: <?php

session_start();

$database_host = "localhost&qu

Displaying different page content, depending on the logged in user.
Hi all, I am new to ASP.net (and web development in general), and have a question about how I can di

PHP5 - Verifying a secure mail is secure
I need to send an e-mail from a form to a external department and because it contains personal custo

Displaying image pathname instead of image
Hello

Im trying to upload and then display images from a mysql database - Its only basic and

removing space from the end of a variable
i have a variable $image which contains the following url "http://tiles.xbox.com/tiles/oo/P5/0m

Structure Question - One Table or One Table Per Record Set?
I have a web app (mySQL and PHP) which allows people to create an item with up to 200 records which

convert pps to wsf with php'how?
hi
i want to convert with php
PowerPoint file to swf file(flash)
how please?
thank!!!

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