Results 1 to 2 of 2
- 11-02-2008, 12:22 AM #1
Member
- Join Date
- Nov 2008
- Posts
- 1
- Rep Power
- 0
How to handle \ (backslash) in regular expressions
I have a client application that presents the user with a dialog and requests input of a regular expression to search on via a text box. The resulting string is passed via a web service call to another application which executes a SQL query against an oracle database using the supplied regular expression.
My problem is that the user has no knowledge of java, but is familiar with regular expressions.
So, for example if they wanted to search for the string "asdf" preceded by a tab, they would enter \tasdf. I believe that java would convert this into an actual tab followed by asdf which is not what I need.
To further complicate matters, if the user wanted to search for the literal string "\tasdf" they would enter \\tasdf.
I think maybe what I need to do is search the string for \ and replace with \\.
Does that sound right? If so how would I handle \\tasdf?
Any help would be much appreciated.
A confused C++ developer.
- 11-02-2008, 01:33 AM #2
The quickest way to find out is to write a small program to test what happens. You can get all sorts of answer from various posters, some of which can be wrong.I believe that java would
There is a difference in how the escape character is handled if you are including a String in a program to be compiled vs a program reading in a String.
Similar Threads
-
Regular Expressions in java
By blue404 in forum Advanced JavaReplies: 2Last Post: 09-26-2008, 03:43 AM -
Using Quantifiers in regular expressions
By Java Tip in forum Java TipReplies: 0Last Post: 01-10-2008, 10:43 AM -
Handling regular expressions using Regex
By Java Tutorial in forum Java TutorialReplies: 0Last Post: 01-07-2008, 12:46 PM -
Capturing Groups using regular expressions
By Java Tip in forum Java TipReplies: 0Last Post: 12-25-2007, 11:19 AM -
Regular expressions quantifiers
By Java Tip in forum Java TipReplies: 0Last Post: 12-25-2007, 11:18 AM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks