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

Create or replace package is ending ORA-21700
Database 9.2.0., patch 8 (9.2.0.8.0).
I trying run
create or replace package ....etc.

for loop without same $i digits?
Hi,

Can some guru please advise how can I accomplish this with a simple for loop ?

I

Blocking video streaming
Hello everyone,

I post a message here because i didn't find any solution yet.
I just finis

Stopping page post back
I have few literal contriols in my page and a repeater too. But inspite of using update panel, postb

retrieving images from mysql database using php
So I've been trying to figure out how to store images in a mysql database, and as far as i can tell

phpmailer class & pop.gmail.com?
Code: <?php
$mail->IsSMTP();
$mail->Host = "pop.gmail.com";

How can use this array as a key?
Say I have this array for example:


print_r($array);

Prints:
Code: [Select]Array

check if string contain only a-z/A-Z
Is where any way to check if string contains only a-z/A-Z, without writing an array with all possibl

[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

GIS appliction help
I found some tutorials in the internet to develop a map application I don't want to use google maps

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