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
Header redirect
Hello ive got a problem ive got form with its action set to itself.
Code: <form id="f
Problem with "dynamic" index page
Hi. I have one question. In my index.php page I have this kind of code:
Code: // listaa sivut
Redirect not working after making a POST/GET
Hi Everyone,
I am a novice in PHP. Here I have 2 pages, one page with a textbox and button an
Help with explandable category tree
I have the below query:
SELECT l1.id as lev1_id,l2.id as lev2_id,l3.id as lev3_id,l1.categ
Refining of search Criteria
Dear Friends
I need a help, I have a search page which of cars related, which has different s
Multiple upload and Resize
I would like some help on my script I have the for my index.php
////
<html&
How to show a complete textarea ??
I enter Client Case Notes notes in a textarea field on a PHP form. The field is 5 rows deep and 70 c
Protecting forms
Alright, I want to protect some forms of mine from SQL Injections, because I had someone earlier spa
Calling variables
I want to call this to my website but it doesn't display what I want it to,
Code: <h5&
ALV grid with 2 headers
Hi Gurus,
I need to display ALV GRID as below.
Header1