Regular expressions-how to replace [ and ] characters from a string

Hi,
my input String is "sdf938 [98033]". Now from this given string, i would like to replace the characters occurring within square brackets to empty string, including the square brackets too.
my output String needs to be "sdf938" in this case.. How should I do it using regular expressions? I tried several possible combinations but didn't get the expected results.

"\\s*\\[[^\\]]+\\]"

Similar Messages

  • How to replace escape characters in a string ?

    Hi All,
    In my application I came across a problem where I want to replace a substring (contains escape characters also) with another string. The below shown code will replicate my problem :
    public class StringSearchAndReplace {
      public static void main(String args[])   {
        String stmt = " \\pntext\\bullet\\tab The question as to ";
        String newStmt = stmt.replaceAll("\\bullet\\tab",  "B");
        System.out.println("BEFORE: " + stmt + "\n");
        System.out.println("AFTER: " + newStmt);
    }Here I want to replace "\\bullet\\tab" with "B". I am unable to move further. Please help/suggest me in this regard.
    Its urgent.
    Thanks in advance.

    Satyaprasad_Mylavarapu wrote:
    Hi All,
    In my application I came across a problem where I want to replace a substring (contains escape characters also) with another string. The below shown code will replicate my problem :
    public class StringSearchAndReplace {
    public static void main(String args[])   {
    String stmt = " \\pntext\\bullet\\tab The question as to ";
    String newStmt = stmt.replaceAll("\\bullet\\tab",  "B");
    System.out.println("BEFORE: " + stmt + "\n");
    System.out.println("AFTER: " + newStmt);
    }Here I want to replace "\\bullet\\tab" with "B". I am unable to move further. Please help/suggest me in this regard.
    Its urgent.
    Thanks in advance.If the String you're trying to replace contains a slash you need four slashes (double it for java, then again because String.replaceAll takes a regular expression)
    So I think what you're looking for is:
    String newStmt = stmt.replaceAll("\\\\bullet\\\\tab",  "B");I haven't tested that though.

  • Does LabView program behave differentl​y under Traditiona​l Chinese version from regular English version. The program reads in numbers and characters from input files.

    Does LabView program behave differently under Traditional Chinese version from regular English version. The program reads in numbers and characters from input files.

    Hope this helps,
    Ankita

  • How to replace NULL values from main table

    Dear all,
    I like to remove the NULL values from a main table field. Or the question is how to replace any part of the string field in MDM repository main table field.
    e.g.   I have a middle name field partly the value is NULL in some hundreds of records, I like to replace NULL values with Space
    any recommendation.
    Regards,
    Naeem

    Hi Naeem,
    You can try using Workflows for automatically replacing NULLs with any specific value.
    What you can do is: Create a workflow and set trigger action as Record Import, Record Create and Record Update. So, that whenever any change will occur in the repository; that workflow will trigger.
    Now create an assignment expression for replacing NULLs with any specific value and use that assignment expression in your workflow by using Assign Step in workflow.
    For exiting records, you will have to replace NULLs manually using the process given by Preethi else you can export those records in an Excel spreadsheet which have NULLs and then replace all NULLs with any string value and then reimport those records in your MDM repository.
    Hope this will solve your problem.
    Regards,
    Varun
    Edited by: Varun Agarwal on Dec 2, 2008 3:12 PM

  • TS1347 Need to know how transfer contacts and messages from an Iphone 3Gs to an iPhone 5s

    how transfer contacts and messages from an Iphone 3Gs to an iPhone 5s

    http://support.apple.com/kb/HT1766

  • I am a new iPad user and cannot figure out how to copy and paste from a website to pages. Any insight?

    I am a new iPad user. I cannot figure out how to copy and paste from a website to a pages document, and vice versa. Any ideas?

    Long press on the text you would like to select (tapping and holding) and then release after the magnifying glass shows up. This will select a single word. Then use the blue dots and drag them to select a region of test. Then press "copy". Open pages, and long press and release where you would like to paste. Then select "paste". That should paste the text.
    If the text doesn't select within the browser, it might be an uncopyable format. Like if the text was within an image, naturally you would be unable to select it. The only thing to do there is long press the image and selecting "save image", adding it to your camera roll. Then you could insert the image within pages.

  • How to export and import from AIX to solaris a whole schema with different

    how to export and import from AIX to solaris a whole schema with different character set
    import done in US7ASCII character set and AL16UTF16 NCHAR character set
    import server uses WE8ISO8859P1 character set (possible charset conversion)
    Import terminated successfully with warnings.

    The conversion between the character sets on the two servers are handled automatically. Export from one server will export the data given the character set defined on that server. Import into another server will import the data given the character set defined on that server, performing a conversion if necessary. This can be a problem when going from single-byte to a multi-byte character set. In your case, the warning is simply for your information, shoule be no real problem given the character sets you're using.
    For more info...check out (pertains to 9i):
    Export
    http://download-west.oracle.com/docs/cd/B10501_01/server.920/a96652/ch01.htm#1006791
    Character Ste Migration
    http://download-west.oracle.com/docs/cd/B10501_01/server.920/a96529/ch10.htm#1656
    HTH

  • My power and volume button is not working how i replace and how much charges??

    my power and volume button is not working how i replace and how much charges??

    $269
    Out-of-warranty* cost:
    iPhone 6 Plus: $329
    iPhone 6: $299
    iPhone 5s, iPhone 5c, iPhone 5: $269
    iPhone 4s: $199
    iPhone 4, iPhone 3GS, iPhone 3G, Original iPhone: $149

  • Removing non-alpha-numeric characters from a string

    How can I remove all non-alpha-numeric characters from a string? (i.e. only alpha-numerics should remain in the string).

    Or even without a loop ?
    Extract from the help for the Search and Replace String function :
    Right-click the Search and Replace String function and select Regular Expression from the shortcut menu to configure the function for advanced regular expression searches and partial match substitution in the replacement string.
    Extract from the for the advanced search options :
    [a-zA-Z0-9] matches any lowercase or uppercase letter or any digit. You also can use a character class to match any character not in a given set by adding a caret (^) to the beginning of the class. For example [^a-zA-Z0-9] matches any character that is not a lowercase or uppercase letter and also not a digit.
    Message Edité par JB le 05-06-2008 01:49 PM
    Attachments:
    Example_VI_BD4.png ‏2 KB

  • Removing characters from a String (concats, substrings, etc)

    This has got me pretty stumped.
    I'm creating a class which takes in a string and then returns the string without vowels and without even numbers. Vowels and even characters are considered "invalid." As an example:
    Input: "hello 123"
    Output: "hll 13"
    The output is the "valid" form of the string.
    Within my class, I have various methods set up, one of which determines if a particular character is "valid" or not, and it is working fine. My problem is that I can't figure out how to essentially "erase" the invalid characters from the string. I have been trying to work with substrings and the concat method, but I can't seem to get it to do what I want. I either get an OutOfBoundsException throw, or I get a cut-up string that just isn't quite right. One time I got the method to work with "hello" (it returned "hll") but when I modified the string the method stopped working again.
    Here's what I have at the moment. It doesn't work properly for all strings, but it should give you an idea of where i'm going with it.
    public String getValidString(){
              String valid = str;
              int start = 0;
              for(int i=0; i<=valid.length()-1; i++){
                   if(isValid(valid.charAt(i))==false){
                             String sub1 = valid.substring(start, i);
                             while(isValid(valid.charAt(i))==false)
                                  i++;
                             start=i;
                             String sub2 = valid.substring(i, valid.length()-1);
                             valid = sub1.concat(sub2);
              return valid;
         }So does anybody have any advice for me or know how I can get this to work?
    Thanks a lot.

    Thansk for the suggestions so far, but i'm not sure how to implement some of them into my program. I probably wasn't specific enough about what all I have.
    I have two classes. One is NoVowelNoEven which contains the code for handling the string. The other is simply a test class, which has my main() method, used for running the program.
    Here's my class and what's involved:
    public class NoVowelNoEven {
    //data fields
         private String str;
    //constructors
         NoVowelNoEven(){
              str="hello";
         NoVowelNoEven(String string){
              str=string;
    //methods
         public String getOriginal(){
              return str;
         public String getValidString(){
              String valid = str;
              int start = 0;
              for(int i=0; i<=valid.length()-1; i++){
                   if(isValid(valid.charAt(i))==false){
                             String sub1 = valid.substring(start, i);
                             while(isValid(valid.charAt(i))==false)
                                  i++;
                             start=i;
                             String sub2 = valid.substring(i, valid.length()-1);
                             valid = sub1.concat(sub2);
              return valid;
         public static int countValidChar(String string){
              int valid=string.length();
              for(int i=0; i<=string.length()-1; i++){
                   if(isNumber(string.charAt(i))==false){
                        if((upperVowel(string.charAt(i))==true)||lowerVowel(string.charAt(i))){
                             valid--;}
                   else if(even(string.charAt(i))==true)
                        valid--;
              return valid;
         private static boolean even(char num){
              boolean even=false;
              int test=(int)num-48;
              if(test%2==0)
                   even=true;
              return even;
         private static boolean isNumber(char chara){
              boolean number=false;
              for(int i=0; i<=9; i++){
                   if((int)chara-48==i){
                        number=true;
              return number;
         private static boolean isValid(char chara){
              boolean valid=true;
              if(isNumber(chara)==true){
                   if(even(chara)==true)
                        valid=false;
              if((upperVowel(chara)==true)||(lowerVowel(chara)==true))
                   valid=false;
              return valid;
    }So in my test class i'd have something like this:
    public class test {
    public static void main(String[] args){
         NoVowelNoEven test1 = new NoVowelNoEven();
         NoVowelNoEven test2 = new NoVowelNoEven("hello 123");
         System.out.println(test1.getOriginal());
         //This prints hello   (default constructor string is "hello")
         System.out.println(test1.countValidChar(test1.getOriginal()));
         //This prints 3
         System.out.println(test1.getValidString());
         //This SHOULD print hll
    }

  • Removing non english characters from my string input source

    Guys,
    I have problem where I need to remove all non english (Latin) characters from a string, what should be the right API to do this?
    One I'm using right now is:
    s.replaceAll("[^\\x00-\\x7F]", "");//s is a string having chinese characters.
    I'm looking for a standard Solution for such problems, where we deal with multiple lingual characters.
    TIA
    Nitin

    Nitin_tiwari wrote:
    I have a string which has Chinese as well as Japanese characters, and I only want to remove only Chinese characters.
    What's the best way to go about it?Oh, I see!
    Well, the problem here is that Strings don't have any information on the language. What you can get out of a String (provided you have the necessary data from the Unicode standard) is the script that is used.
    A script can be used for multiple languages (for example English and German use mostly the same script, even if there are a few characters that are only used in German).
    A language can use multiple scripts (for example Japanese uses Kanji, Hiragana and Katakana).
    And if I remember correctly, then Japanese and Chinese texts share some characters on the Unicode plane (I might be wrong, 'though, since I speak/write neither of those languages).
    These two facts make these kinds of detections hard to do. In some cases they are easy (separating latin-script texts from anything else) in others it may be much tougher or even impossible (Chinese/Japanese).

  • How to replace a character in a string with blank space.

    Hi,
    How to replace a character in a string with blank space.
    Note:
    I have to change string  CL_DS_1===========CM01 to CL_DS_1               CM01.
    i.e) I have to replace '=' with ' '.
    I have already tried with <b>REPLACE ALL OCCURRENCES OF '=' IN temp_fill_string WITH ' '</b>
    Its not working.

    Hi,
    Try with this..
    call method textedit- >replace_all
      exporting
        case_sensitive_mode = case_sensitive_mode
        replace_string = replace_string
        search_string = search_string
        whole_word_mode = whole_word_mode
      changing
        counter = counter
      exceptions
        error_cntl_call_method = 1
        invalid_parameter = 2.
    <b>Parameters</b>      <b> Description</b>    <b> Possible values</b>
    case_sensitive_mode    Upper-/lowercase       false Do not observe (default value)
                                                                       true  Observe
    replace_string                Text to replace the 
                                         occurrences of
                                         SEARCH_STRING
    search_string                 Text to be replaced
    whole_word_mode          Only replace whole words   false Find whole words and                                                                               
    parts of words (default                                                                               
    value)
                                                                               true  Only find whole words
    counter                         Return value specifying how
                                        many times the search string
                                        was replaced
    Regards,
      Jayaram...

  • How to create session id from different string controls

    how to create session id from different string controls

    fais,
    Please create the VI you are talking about and save some default data into all of the controls. Also on the front panel, place the session ID that should be generated by that data. Now, post your VI to a response so I can download it. I can then take this VI and help you create the functionality. (Please post what version of LabVIEW you are using.)
    My guess it that you are going to need to use a good number of string concatenations as well as a few string indexes to get parts of strings out. As for the date, you can use a Property node with the Numeric Text.Text property to get the actual string displayed on the front panel for the date and parse out the parts that you want.
    Randy Hoskin
    Applications Engineer
    National Instruments
    h
    ttp://www.ni.com/ask

  • How to get a char from a String Class?

    How to get a char from a String Class?

    Use charAt(int index), like this for example:
    String s = "Java";
    char c = s.charAt(2);
    System.out.println(c);

  • SQL Injection and Java Regular Expression: How to match words?

    Dear friends,
    I am handling sql injection attack to our application with java regular expression. I used it to match that if there are malicious characters or key words injected into the parameter value.
    The denied characters and key words can be " ' ", " ; ", "insert", "delete" and so on. The expression I write is String pattern_str="('|;|insert|delete)+".
    I know it is not correct. It could not be used to only match the whole word insert or delete. Each character in the two words can be matched and it is not what I want. Do you have any idea to only match the whole word?
    Thanks,
    Ricky
    Edited by: Ricky Ru on 28/04/2011 02:29

    Avoid dynamic sql, avoid string concatenation and use bind variables and the risk is negligible.

Maybe you are looking for

  • "CALL_FUNCTION_CONFLICT_TYPE" runtime error while running tcode BPS0 in BW

    Hi , Can anybody have any idea about this dump error in BW quality system while user running tcode BPS0 and getting this dump repeatedly please help me out on this. Error in the ABAP Application Program The current ABAP program "SAPLZBSV_BPS_E_PLA_VA

  • Error 1 while building in 8.2

    This error below occurs when I build. I try to put a path into the destination path but it does not get saved. I have tried the entry in the destinations folder entry and the Application information. I have copied the path and also selected the path

  • How to specify image directory in Tomcat servlet?

    The following will display the counter.png image stored in my Tomcat webapps/ROOT/images directory (even from a servlet at webapps/counters):outText.println("<IMG SRC=\"/images/counter.png\">");but what's the magical incantation to get at webapps/cou

  • Files encrypted and digital signed with cFolders

    Dear all, Currently I'm involved on a PPS project with cFolders. This project has legal requirements that consist in implementing encryption and digital signature in files which will be uploaded to cFolders. I've been searching on SAP Help, SDN and S

  • Only last 2 days of facebook news feed in Social A...

    I'm only getting the last 2 days of my facebook news feed in the Social App.  It seems to happen in fMobi as well.  Is this a Nokia thing or possibly Facebook restriction...??? Any ideas???