Results 1 to 2 of 2
  1. #1
    federal102 is offline Member
    Join Date
    Nov 2008
    Posts
    1
    Rep Power
    0

    Default 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.

  2. #2
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    17,560
    Rep Power
    25

    Default

    I believe that java would
    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.
    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

  1. Regular Expressions in java
    By blue404 in forum Advanced Java
    Replies: 2
    Last Post: 09-26-2008, 03:43 AM
  2. Using Quantifiers in regular expressions
    By Java Tip in forum Java Tip
    Replies: 0
    Last Post: 01-10-2008, 10:43 AM
  3. Handling regular expressions using Regex
    By Java Tutorial in forum Java Tutorial
    Replies: 0
    Last Post: 01-07-2008, 12:46 PM
  4. Capturing Groups using regular expressions
    By Java Tip in forum Java Tip
    Replies: 0
    Last Post: 12-25-2007, 11:19 AM
  5. Regular expressions quantifiers
    By Java Tip in forum Java Tip
    Replies: 0
    Last Post: 12-25-2007, 11:18 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •