String replaceAll() help

    //kill characters method used to remove unwanted characters
    //from strings, takes in unedited string, returns formatted string
    private String killChars(String fixThis )
    {
        return fixThis.replaceAll("\\W", "");
    }//end
Hey guys and girls.

I have this method in one of my applications and I do not exactly get the results I want. Is there a way to manipulate the replaceAll function arguments so that it will replace all non alphanumeric except for spaces? In fact, I want to keep white space.

Thank you

Kyle

I think you can use "[^ \\s\\w]", which is anything other than whitespace or Word because. try it, see if it does what it takes.

Tags: Java

Similar Questions

  • String.replaceAll () takes an argument of regex?

    For the experienced:


    It is not not to solve a problem to find work on hand made, but something for the discussion of other possibilities.

    I have a file which must cut them before use. The file has several lines, and for each line of the format is ('X' is used to mark the beginning and the end of the line to show the invisible white space):
    X12345678   9876543210 X
    I need to replace the three spaces between two numeric characters with one and eliminate space of tailings. My code:
    String line = null;
    while ((line = inputStream.readLine()) != null) {
        Pattern pattern = Pattern.compile("\\s+");
        Matcher matcher = pattern.matcher(line);
        line = matcher.replaceAll(" ").trim();
        System.out.println("(" + line + ")");
    Which works very well and produces the desired result:
    (12345678 9876543210)
    Would but not be simpler if replacement of the String class methods would do the same job? It is, say,
    String line = null;
    while ((line = inputStream.readLine()) != null) {
        line.replaceAll("\\d+", " ").trim();
        System.out.println("(" + line + ")");
    I do this using JDeveloper 11.1.1.3, located in C:\Oracle\Middleware\jdeveloper\jdeveloper.exe and found out, C:\Oracle\Middleware\jdk160_18\jre\bin\client\jvm.dll is probably the JDK using the JDeveloper. I checked the API document online for Java version 6 to http://download.oracle.com/javase/6/docs/api/index.html, and it shows that the String class has these replacement methods that take the regex:
    String replaceAll(String regex, String replacement) 
    String replaceFirst(String regex, String replacement) 
    But when coding, typing < font color = "green" > replace < / police > as a result of the variable string < font color = "green" > line < / police >, all the insight of Code appears include:
    replace(Char, Char)                  String
    replace(CharSequqnce, CharSequence)  String
    replaceAll(String, String)           String
    replaceFirst(String, String)         String
    This seems to say that regex is not supported. If I do not take into account the suggestion of the foresight of Code and try anyway:
    line.repaceAll("\\d+", " ");
    
    or
    
    line.replaceAll("  *", " ");
       // This second attempt uses the familiar regular expression in unix,
       // such as would be used in
       // $ echo $line | sed 's/  */ /g'
    JDeveloper complain about this attempt. But it does not work either, simply echo back which entered into him.

    What I want to do is play with it to find a way of writing acceptable regular expressions in the JDK in JDeveloper. What the API documentation has said is that regex is accepted and taken in charge, but his behavior, we know not if this is the case with the JDeveloper, or if it is supported, but the suggestion of the insight of Code isn't fair and my regular expressions are not correct.

    All suggestions and insight would be much appreciated.


    Newman

    System.out.println ("1 2 3 4".replaceAll ("\\s {2},", "X")); is back "X 1 2 X 3 X 4"(p. ex. espaces consécutifs seulement sont obtenant remplacés). "»
    I have not tested, but the \s character class may not include new lines. You can use \n If you want to include line breaks as well. Also, I used JDeveloper and jdk, I used is one that comes with Jdeveloper(e.g. \Oracle\Middleware\jdk160_21).

    Edited by: Hyangelo may 9, 2011 11:03

    Edited by: Hyangelo may 9, 2011 11:05

  • problem with String.replaceAll

    Everyone does not understand why "10,00".replaceAll (".") * ","0") == '00' and not '0'?"

    Looks like. * must match the whole string and replace it with '0 '.

    With the help of 1.6.0_17

    840419 wrote:
    Everyone does not understand why "10,00".replaceAll (".") * ","0") == '00' and not '0'?"

    Looks like. * must match the whole string and replace it with '0 '.

    He does.

        public static void main(String[] arg) {
            //System.out.println("10.00".replaceAll(".*", "0"));
            Pattern p = Pattern.compile(".*");
            Matcher m = p.matcher("10.00");
            while(m.find()) {
                // the first find() greedily matches everything
                // the second find() matches a 0(zero)-length charsequence at the end
                System.out.printf("[%s]\n",m.group());
            }
        }
    

    You want to

        public static void main(String[] arg) {
            //System.out.println("10.00".replaceAll(".+", "0"));
            Pattern p = Pattern.compile(".+");
            Matcher m = p.matcher("10.00");
            while(m.find()) {
                System.out.printf("[%s]\n",m.group());
            }
        }
    
  • Hexadecimal string parsing help

    Hi I have a problem with this problem. I use XBEE in API mode and features how it works it sends a string of package API containing the address, length, and data. I have no problem separating those is just when the data comes. If devices expires or is interrupted by another node, it sends the packet but it cannot send a complete data package. For example, it is just part of the data that it sends:

    02CB 33FA FFD4 331D 00AF 3304 00CA 33FB FFD3 331D 00AF 3303

    At the beginning of each data byte is 0 x 33 or 0 x 34, followed by more than 3 bytes. As you can see he has not finished the last byte of data (3303) the rest of the data is contained in the beginning of the next package that would be:

    02CB 33FA FFD4 331D 00AF 3304 00CA 34FB FFD3 00AF 3305 331D

    Thus, the finished data would be 3303 02CB. I'm having a lot of trouble with between them each data packet and adding on a string of incomplete data.

    It's an interesting way to use the input of the splitter in the chain of worksheet to the array function.

    The images below show a simple approach, I think that's what you want.  The part of the code not shown is a shift register.  The string from the left is connected to the shift register terminal to the left.  The first string to right connects to terminal of shift register to the right. The shift register is initialized with an empty string.  The lowest string on the right connects to a terminal autoindexing and creates the table shown in the results.  The constant related to the terminal Regular Expression is defined in "Hex" mode  Read the help for the match pattern for more information on how it works.  Rather than the table would connect you your function to queue for the indicator of substring matching.

    This code replaces all in the structure of your business.

    Lynn

  • RegExp string transform help

    Hello

    My version of Oracle: 11G

    Here is a string I get in a flat file:

    2009-01 - 01 T 14: 02:02.789

    My requirement is to transform in 2009-01-01 14:02:02

    (1) T must be replaced by a space

    point 2) and the characters that follow must be replaced by null

    PS: I realized using multiple functions, but you are looking to do this using a function only, I guess regexp_replace might help me thereby or is it does nothing else.

    Concerning

    Rahul

    One more way!

    regexp_replace ('2009 - 01-01 T 14: 02:02.789 ',' t |) () \. [[ : digit :]] * $) «, » ')

  • ActionScript 3 String Match() help

    Hello

    I have a several of the hyperlinks on a Web page and I only need to store a few who have a certain rhythm in a variable/table.

    I discovered that you can do this with the match() function. I loaded the container on the Web page in a chain, so I'm just using the MATCH function to try to find the model. The problem is, I'm not bad with reg expressions.

    The hyperlinks I want to catch are written as follows: < a href = "/somename/sameForAllFilesfile.sz" > link < /a > Some

    I only need to store the content between the href =' and ' >.» The file 'sameForAllFiles' is what is common for all files and what I'm trying to use the EQUIV, but I can't get the right expression. Can someone write a basic example of code that I could use?

    Thank you!

    If you use the 'match' method, so that:

    var string: String = "blablabla\

    Some link blablabla\

    Some Link2.

    Some Link3';

    //

    var directoryTemplate:String = ' / sameForAllFiles / ';

    //

    [var regSource:String = '<><>] + href = "[^" "] +" + directoryTemplate + "[^" "] +" [^<>] * > ';

    var reg: RegExp = new RegExp (regSource, 'g');

    //

    trace (String.match (REG));

    Result:

    ,,

  • String conversion help please

    Hi all

    I'm trying to convert the following text:

    ROOM_NUMBER

    MMA-A13_03
    MMA-B13_04
    BOWL - 23 C
    BOWL - 16 C
    CUP-06F

    Select distinct replace (replace (substr (ROOM_NUMBER, instr (ROOM_NUMBER, '-'), 10), '-'), '_', '-') table Short_Room;

    A13-03
    B13-04
    23 C
    16 C
    06TH

    If the first character is a letter that replace it with anything?

    i.e.

    A13 - 03 will become 13-03

    Hmm... You can play a little yourself with REGEXP with the help of Solomon.
    Replace (REGEXP_REPLACE (regexp_replace(room_number,'^[^-]+-\a{0,1}'), '[A - Z].'), '_','-')

  • Adding string Please HELP!

    Hello

    I need to know that action script uses to add channels to the formatting variables.

    For example, I have this code

    public void addString(str1:String):void

    {

    For (i: int = 0; i < data.length; i ++)

    {

    trace (data [i] .str1)

    }

    }

    of course, this does not work but what is the format for the string to properly attached at the end of the data [i]. ??

    trace (data [i]. {} str1});<---something like="" this?----="">

    To get a property defined by a writing value string variable:

    data [i] [str1]

    data [i] are an object of your collection and data [i] [str1] are the property of "str1" of this object.

  • Determine if a string contains an expression of certain

    Hi all

    I feel that there should be a simple way to do this, but I was not able to understand after browsing these forums, the help of LV and Google.

    I just want to get in a string and returns true if it is false if is not to determine if it contains a certain expression. I understand there are regular expression screw, as model of matching and Match Regex, but those who return substrings; I want just a Boolean value returned. I could use the VI regular expression corresponds to analyze output strings to determine if it finds a match and returns a Boolean value from there, but I feel like there is a way better and simpler I forget.

    In the subpalette of 'additional string functions' I see there first Match string and string of true/false game, but using the first Match string seems like it would complicate what I try to do, and I don't yet know what game true/false String; detailed help is always confusing.

    Thanks for any help!

    There are simple ways. Read the help associated with search string functions! Each of them returns the offset of the found string. It is - 1 if it is not found. A simple function to Less Than Zero can be connected to this to return a Boolean value. Another way is to compare the substring returned by the function of empty string.

  • concatenate a string and a sequence number

    Hey guys,.

    I use jdeveloper Studio Edition Version 11.1.2.1.0.

    I would attribute a sequence that I have attached a string to my PK as a AP2013081000 attribute.

    Could someone help how the above application can be achieved in the adf?

    Here are the trigger and how could I use it to record in my attribute?

    create or replace

    LEARNER_TRG RELAXATION

    INSERT BEFORE ON THE LEARNER

    FOR EACH LINE

    BEGIN

    < < COLUMN_SEQUENCES > >

    BEGIN

    IF: NEW. STUDENTNO IS NULL OR: NEW. STUDENTNO < 0 THEN

    SELECT TO_CHAR ("AP": to_char (sysdate, 'YYYYMM') |) LEARNER_SEQ. NEXTVAL) IN: NEW. STUDENTNO FROM DUAL;

    END IF;

    END COLUMN_SEQUENCES;

    END;

    I used the DBSequence data type

    only for the

    LEARNER_TRG RELAXATION

    INSERT BEFORE ON THE LEARNER

    FOR EACH LINE

    BEGIN

    < < COLUMN_SEQUENCES > >

    BEGIN

    IF: NEW. STUDENTNO IS NULL OR: NEW. STUDENTNO < 0 THEN

    SELECT to_char (sysdate, 'YYYYMM') | LEARNER_SEQ. NEXTVAL INTO: NEW. STUDENTNO FROM DUAL;

    END IF;

    END COLUMN_SEQUENCES;

    END;

    Kind regards

    Steve

    You should be able to use the groovy for that approach. In this case you needn't pl/sql. Binary decompilation ADF: Groovy expression for assignment DB Sequence value for an attribute of type String should help you get started.

    Timo

  • Strange error Please Help

    Hi friends


    the query
    SELECT nvl(SUM(NET_WEIGHT_FARMER),0) FROM WEIGHT_SLIP where weight_out > 0 and weight_out_date between to_date(trunc(sysdate - 1) || ' 04:00:00','dd-mon-yy hh24:mi:ss') and to_date(trunc(sysdate) || ' 04:00:00','dd-mon-yy hh24:mi:ss')
    This query runs perfectly my php code using oci_execute but the query even when it is used in VB6 returns the following error

    OIC-01861: literal does not match the format string

    Kindly help


    Concerning
    Parikshit

    Your conversion rate of date is all wrong...

     to_date(trunc(sysdate - 1) || ' 04:00:00','dd-mon-yy hh24:mi:ss')
    

    This:

    trunc(sysdate - 1)
    

    Returns a DATE data type

    This:

    trunc(sysdate - 1) || ' 04:00:00'
    

    attempt to concatenate a string of VARCHAR2 to the DATE dataype, causing the DATE to be implicitly converted to a string according to your local NLS_DATE_FORMAT settings (* which may differ between environments), giving you a potentially unknown format in your chain.

    You then take this string of unknown format potentially and:

     to_date(trunc(sysdate - 1) || ' 04:00:00','dd-mon-yy hh24:mi:ss')
    

    ... to tell things to convert it to a DATE data type based on the format "LUN-JJ-AA hh24:mi:ss' which can be or not what the string is.

    I think you just want something like:

    trunc(sysdate-1)+(4/24)
    

    which truncates the value of DATE for the next day (i.e. to reset the time to 00:00:00, then add 4 hours to it.

  • Match Pattren problem

    Hello

    I use the match function String pattern in Labview to search for the string. I'm getting it's say I strings in order

    ABC

    Test1

    Test

    If I give Test has a regular Expression for the game, I get output matched for Test1, I mean before the substring is ABC, substring matching is trial and after substring is 1 Test.  I'm lookinh for the 3rd line. I have no commas or points at the end of the string. Help, please

    Well, you might have the look of search for "Test\n" or 'Test\r\n' according to your format.  You will then match on a string that has a line that ends with 'Test '.  Of course, this works only if the Test is not the last line in the file.

    Yes, the regular expression would probably be easier.

  • Classic blackBerry BB classic OS10 battery monitor bug

    Not sure why a company of the size of the Blackberry Limted cannot host JPEG files on their server for troubleshooting purposes.  If an admin email me, I will answer with screenshots.

    Anywho, the use of battery controller, located inside devmon has a cool little chart that has recently been distorted (hard to explain without screenshots) when you use the option ' since last Charge. I use the Release10.3.2.556/OS Version of the 10.3.2.858 software. On AT & T.

    Hello and welcome to the community!

    wtfeva wrote:

    Not sure why a company of the size of the Blackberry Limted cannot host JPEG files on their server for troubleshooting purposes.

    It's a thing of spam prevention... you must post a number of times before you can include pictures. I don't remember how much, but I remember there are some minimum number of messages, you need to do before that is allowed. Be a totally public forum, getting us slammed with spam a lot.

    wtfeva wrote:

    If an admin email me, I will answer with screenshots.

    There are no admins here... see:

    I hope that this information will be useful to you. It is a community of users, not a string all help really formal BB, your carrier, etc.

    wtfeva wrote:

    Anywho, the use of battery controller, located inside devmon has a cool little chart that has recently been distorted (hard to explain without screenshots) when you use the option ' since last Charge.

    Has nothing changed just before this behavior started? A new application? An update of sorts?

    Did you base... restart?

    wtfeva wrote:

    I use the Release10.3.2.556/OS Version of the 10.3.2.858 software. On AT & T.

    It's a pretty old OS now... I don't know what AT & T is on your model, but the most recent production OS is 10.3.2.2789... much further along 858. If the automated methods don't offer it, then you can consider using unofficial methods to get it.

    If you can't think of something of causal (from above) or if you want you can move to a more recent operating system level, these methods are available:

    Official methods, which will be controlled as to what exact OS versions are available:

    Non-official methods, which are cleaner and allow you to choose a version of the OS that maybe your carrier (or anyone they control your offers) delays in approval:

    Of course, before you start this, you want a good backup link, a manual copy of the memory of your device to your PC and complete documentation of your configuration (identification information of account, adding applications, configurations, etc.). Sometimes, restoring a backup returns unit corruption even, must be eliminated and reconfiguration from scratch can solve that.

    Be aware of the risks of 10.3.2 however... There are two things to worry about. First of all, be 100% sure that you know your BBID identifiers... If you do not, you may make your useless device to anyone, including yourself. Second, once you move to 10.3.2, you cannot fall back to 10.3.1 or earlier, by any medium (for example, even the unofficial AutoLoaders can not overcome this restriction anti-secours).

    Good luck!

  • How do to this chain operation looks simple but causing a lot of time to do :)

    Hi all

    I have a very large chain, i.e. the soap xml response send by server that I read once connected to the server using http, now the problem is that I need to create a Document out of it and analyze what is simple but the answer I get server requires many replacements of string as example 1) replacing "<" with "<"  2)="" replacing="" ">"="" with="" "="">" etc before creating a document out of it now there are many such replacements in the sending of the response from server that takes a lot of time. 5 minutes on the emulator. So my question is how do? Is there a native method to replaceAll occurrences of a substring in a string or while I can use or is there another good way? Please let me know thx.

    Thank you

    Sagar

    We took over a project done by someone else, and they were doing exactly what you do.  Here is their source, which I think is more effective that you give it a try if you want.

    But be aware that I have never used or tested this code.

    I guess you pull that string to the center of your SOAP response.  It has been encoded XML.  So you can do what we did in this case and wrap the string as a data element in an XML element and then use the XML parser to get the actual data, which feed us an XML parser again to get the actual data.  XML is already set up to deal with these characters, so it was more effective than the approach to replace.  Actually to be honest, it wasn't the reason we exchanged, that as part of the parser XML meant we were convinced it was done correctly.

     public String replaceAll(String source, String pattern, String replace) {
            if ((source != null) && (pattern.length() > 0)) {
                final int len = pattern.length();
                StringBuffer sb = new StringBuffer();
                int found = -1;
                int start = 0;
    
                while ((found = source.indexOf(pattern, start)) != -1) {
                    sb.append(source.substring(start, found));
                    sb.append(replace);
                    start = found + len;
                }
    
                sb.append(source.substring(start));
                return sb.toString();
            } else
                return "";
        }
    
  • TileList only keeping not with class data order custom CellRenderer

    Hi all

    I was hoping that you guys could help me with this, I did a search and nobody seems to know the same problem.  So first the installer: I have a TileList component set in place with a line in.  The TileList component using a custom class that extends the CellRenderer class to view its data. The problem is that if I scroll so the first element is not visible, in addition, its value is replaced by another item in my dataProvider.

    Here is my code for the CellRenderer class (where I am assuming that the problem):

       public class MyRenderer extends CellRenderer
        {
            private var renderer:MyDataDisplay = new MyDataDisplay();
            public function MyRenderer()
            {
                super();
            }
    
            override protected function onAdded():void{
                super.onAdded();
                addChild(renderer);
            }
    
            override protected function onRemoved():void{
                super.onRemoved();
                removeChild(renderer);
            }
    
            override protected function drawLabel():void{
                super.drawLabel();
                if(data){
                    renderer.title.text= data.name as String;
                    renderer.date.text = data.date as String;
                }
            }
    

    Help?

    Hey cyangreen,

    lists and cell renderers are the heels of achilie of the QNX API when it comes for them to find haha. and once you think u he descended, something unexpected happens and you have to change once again lol.

    I met problems here and there, and usually when you define the data and what not, I substitute the public data() setter. like this I get accurate results. the list and CellRenderer do things funky sometiems and get weird to read outs. so try to do this and see if it changes anything. So instead of override the drawLabel() method, replace the set data() accessor:

    override public function set data(data:Object):void
    {
        super.data = data;
    
        if (data.name && data.data)
        {
            renderer.title.text= data.name as String;
            renderer.date.text = data.date as String;
        }
    }
    

    Let me know how that turns out. If it doesn't work, let's try something else. Good luck!

Maybe you are looking for

  • Pass data to another loop event loop

    I'm trying to find a simple way to pass data to a loop of events for use elsewhere.  Could someone explain to me why my example below block (code attached)?  I feel that I must be missing something simple.  Also, I would rather avoid queues, if possi

  • Screen saver slide show displays all the images

    original title: screen saver I chose pictures like under settings and screen saver, I choose my photos but it doesn't work because of a couple of records not all.  Why?

  • Puppet stuck outside the parameters of the scene

    I replace the Frankenstein's head with my own diapers and now, for some reason any when I drag the puppet in the scene it turns off the announcement of edge I can't move it.I removed the layer of "Fur from his head", which would have something to do

  • Cannot open /CS (ContentServer) in environment of delivery in the Webcenter Sites?

    HelloI installed webcenter sites 11.1.1.6 on windows 7 using single mode and delivery server environment.server_wcs_PRD01 - managed server application is deployed on which CS - port number 7113server_cas_PRD01 - managed server application is deployed

  • Performance network graph

    Hi guys,.I was to check the performance of the network the other day and noticed traffic envoys was bigger that the traffic received then 28 VMs were playing a video. Is this a phenomenon EXPECTED? Consider the traffic from the internet to NIC as tra