Replace comma  with a character only if it is enclosed in single quotes

I have a string
String stmt = "insert into ABC values (Default,'ABC','1234,xyz,abc');{code}
expected the result is
insert into ABC values (Default,'ABC','1234~xyz~abc')
I want to replace only those commas with a ~ if they are part of the string enclosed in a pair of singe quotes.
i am trying something like
{code}String regex = "\'\\w+(,)+\\w*,*\\w*\'+\1";
String output = stmt.replaceAll(regex,"~");
{code}
but its not working
Please help.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       

LearningMachine wrote:
No, that's not what I am trying to do.
This is not an insert into a sql, I have to parse a DML (SQL Script) and get table name, values out of it, but I can't split the string with commas.
Then you should find or build a parser.
Unless the DML is very well constrained or the set is very small and will remain so, by the time you finish mucking around with all the possibilities attempting it with regexes you will have a parser but not a very good one.

Similar Messages

  • Replacing comma with space

    Hi,
    Note : I am using SAP 4.6
    Task      : Replace Comma with space
    Problem : Not able to replace comma with space
    I have task where I have to write result file to application server, when I am writing string to application server it is separating by comma, for example if you take below statement it is dividing by space that means in first column PO and then ITEM etcu2026.
    MOVE  'PO ITEM is not there in table EKPO' TO W_RECORD_OUT-ERROR_MSG.
    so to resolve this situation I have used below code for now, I know I can use
    REPLACE ... ALL ENTRIES but this statement is not working in SAP 4.6
    REPLACE ',' WITH ' ' INTO W_RECORD_OUT-ERROR_MSG.
      CONDENSE W_RECORD_OUT-ERROR_MSG.
      REPLACE ',' WITH ' ' INTO W_RECORD_OUT-ERROR_MSG.
      CONDENSE W_RECORD_OUT-ERROR_MSG.
      REPLACE ',' WITH ' ' INTO W_RECORD_OUT-ERROR_MSG.
      CONDENSE W_RECORD_OUT-ERROR_MSG.
      REPLACE ',' WITH ' ' INTO W_RECORD_OUT-ERROR_MSG.
      CONDENSE W_RECORD_OUT-ERROR_MSG.
      REPLACE ',' WITH ' ' INTO W_RECORD_OUT-ERROR_MSG.
      CONDENSE W_RECORD_OUT-ERROR_MSG.
      REPLACE ',' WITH ' ' INTO W_RECORD_OUT-ERROR_MSG.
      CONDENSE W_RECORD_OUT-ERROR_MSG.
      REPLACE ',' WITH ' ' INTO W_RECORD_OUT-ERROR_MSG.
      CONDENSE W_RECORD_OUT-ERROR_MSG.
      REPLACE ',' WITH ' ' INTO W_RECORD_OUT-ERROR_MSG.
      CONDENSE W_RECORD_OUT-ERROR_MSG.
      REPLACE ',' WITH ' ' INTO W_RECORD_OUT-ERROR_MSG.
      CONDENSE W_RECORD_OUT-ERROR_MSG.
      REPLACE ',' WITH ' ' INTO W_RECORD_OUT-ERROR_MSG.
      CONDENSE W_RECORD_OUT-ERROR_MSG.
      REPLACE ',' WITH ' ' INTO W_RECORD_OUT-ERROR_MSG.
      CONDENSE W_RECORD_OUT-ERROR_MSG.
    appreciate if somebody can help me.
    Thanks
    sarath

    Hi,
    Please check the below code.
    REPORT  YSAT_TEST.
    Data: Var1(40) type c value 'Test1,Test2,Test3,Test4'.
    break-point.
    REPLACE ',' WITH space INTO Var1.                   " It will replace only first occurrence
    replace all occurrences of ',' in var1 with '   '.
    CONDENSE Var1 no-gaps.
    write: var1.

  • Replacing comma with Javascript

    Hi,
    How to replace commas in an array with Javascript???
    For eg, i have an array that contain the values 1,2,3,4.
    Here i want to remove the comma. So the solution i am looking for is
    1234.
    How to do this. Can we the Java functions like replace() in javascript?
    How to import the Java classes in Javascript???
    Please do provide a solution for this.
    Regards,
    M.Ananthu

    I'm not aware of any mechanism in Javascript that can help with this. In our fully-internationalized web applicaiton we choose to perform all locale-dependent validation server-side. This includes dates, numbers, currency values etc. About the only thing we check in Javscript is that required fields are filled in.
    I'd be interested in knowing if anyone has solved this in Javscript. Its possible that you could dynamically generate a Javscript validation routine based on the locale-specific formatting symbols, but we decided it wasn't worth it.
    T

  • Replace comma with dot

    Dear all,
    I'm getteing mad with the following issue and need your help.
    I'm working at a PDF-Form including a table. The Values in this table create a datamatrix. This works fine for now.
    Here is my issue: The values in the table are numbers like 12.2 but also 12 or 9 but maximum two digits in front of the "."(dot). Seperation character should be a "." In Germany there is the ","(comma) instead of the "." at the number block.
    For better usability it would be nice having a java script that replaces onBlur all "," with a ".". So I don't have to change the keyboard language to English.
    Is this possible and if yes, how?
    I am an absolutely noob on javascript, so please be patient and do not expect any specific knowledge.
    What I tried (menue is translatet from the German version, I don't know if it is correct:
    onBlur.replace(",", ".");
    I put this in (right click on form) -> properties ->action ->
    add action: on mouse exit
    choose action: run JavaScript
    click on "add"
    Then I copied the terminus from the top in the opening window. Ready (at least this was my thought...)
    It dit not work, now I nedd your help.
    Thank you for your hints, your help and your time.
    Adobe Acrobat XI (German) on Windows 7 64bit (also german).

    ***************SOLVED**********************
    The solution was much easier than expected:
    when you open "properties" by right clicking on the form, go to "validation" NOT "action" (make sure you are in the form editing mode: "tools" -> "forms" -> "edit")
    then chose "run user defined script" and click on "edit"
    type in the following line:
    event.value = event.value.replace(/\,/g, ".");
    click "OK" and then "Close"
    Then you are done. Now, when you leave the form field Acrobat checks if there is a comma and replaces it with a dot.
    For me this was the easiest way to make it work.
    ***************SOLVED**********************
    ***************GELÖST**********************
    Die Lösung war einfacher als gedacht.
    Öffnet man "Eigenschaften" mit einem Rechtsklick auf das Formular, muss man "Validierung" und nicht "Aktionen" auswählen. (man muss im Formulareditierungsmodus sein: "Werkzeuge" -> "Formulare" -> "Bearbeiten")
    dann unter "Benutzerdefiniertes Validierungsskript ausführen" auf "Berabeiten" klicken.
    Im Editorfenster folgende Zeile eingeben:
    event.value = event.value.replace(/\,/g, ".");
    Über "OK" und "Schließen" zurück zu den Eigenschaften
    Das war's. Nun ersetzt Acrobat im Formularfeld jedes Komma durch einen Punkt.
    ***************GELÖST**********************

  • Replace comma with nothing

    Hi all
    In a select statement I need to delete the commnas in a string that has a number with commas.
    i.e replace 1,123.10 by 1123.10

    select replace(col,',') from table

  • HELP : Replacing Space with any character !

    Hi !
    How do I replace any spaces in a strings passed from a FORM INPUT, with a different character.
    I tried doing this
    String s= request.getParameters("info");
    s.replace(' ','_');
    But it keep giving me error.
    it there any simpler way of doign this?
    Thank you
    K

    Hi !
    I am new to JSP,
    It keep giving a null pointer exception when i use it with JSP
    So i did this it work fine on the try section
    and once it is in the catch section it keeps giving me Nullpointer exceptions again.
    IS there any other way replacing the space with a "-" or anything..?
    Thanks for your help.
    here is the code
    String r_space ="";
    try {
         r_space=value.replace(' ','+');
         out.println("r_space : try " r_space "<br>");
    catch(NullPointerException e) {
    System.out.println("Recaught: " + e );
    r_space=value.replace(' ','+');
    out.println("r_space : cathc" r_space "<br>");

  • How replace comma with break line

    Hi, 
    Instead of John,Dee, i want it to show
    John
    Dee.
    my code isn't do what i want, can anyone help pls?
    thanks
    <cfset mystring ="John,Dee" />
    <cfset TheText = replace(mystring, ',', "#chr(10)##chr(13)#", "ALL") />
    <cfoutput>
    #TheText#
    </cfoutput>

    Yeah.  If you're gonna go ACTUAL HTML output, then forget the line break and just put each indexed value into a <p> tag (which, because it's a block-level element, will place it on each line)
    <cfset myList = 'Aegis,Kleais' />
    <cfoutput>
    <cfloop list="#myList#" index="i">
         <p>#i#</p> 
    </cfloop>
    </cfoutput>
    This should output:
    Aegis
    Kleais
    The spacing between the text can be controlled via CSS.

  • Replacing the ul bullet with a character (no image)

    Can this be done? All the tutorials I've found via Google explain how to replace the bullet by an image. I'm looking to replace it with a character (like ★ or ♬)

    Yes. You could do this with the CSS before selector and HTML special characters.
    http://designshack.net/articles/css/the-lowdown-on-before-and-after-in-css/
    You need to use an utf-8-charset
    ul li {list-style:none}
    li:before {
    content:'\266b';  /**musical note**/
    padding-right: 12px;
    font-family: Times, serif;  /**for consistency**/
    Nancy O.

  • Repalce comma with Space in Webi report.

    Hi Experts,
    My address Column in Webi report is showing data is like :
    Address (this is the field coming for BW)
    House No1,Flat J10,New Delhi,INDIA.
    Can we replace Comma with the space so that the ablove data would be like :
    House No1 Flat J10 New Delhi INDIA.
    Thanks.

    Hi Abdi
    Use the formula
    = Replace("House No1,Flat J10,New Delhi,INDIA";",";" ")
    then you will get
    House No1 Flat J10 New Delhi INDIA.
    Use the object in place of Text
    =Replace([Address];",";" ")
    Regards,
    Mahi

  • Can I quote a single quote character so that I can use it in Replace()

    Hi. How can I quote a single quote character so that I can use it in the Replace() function below. I'm attempting to query first_name records that contain a '.
    select first_name, last_name
    from ttms.prospect
    where instr(first_name,"'") > 0
    ERROR at line 3:
    ORA-00904: "'": invalid identifier

    Hi,
    String literals are enclosed in single-quotes (not double-quotes).
    To use a single-quote within a string literal, use two of them:
    WHERE   INSTR (first_name, '''') > 0In Oacle 10 (and up) you can also use Q-Notation:
    WHERE   INSTR (first_name, q'[']') > 0but you may find this more confusing for short literals containing only one single-quote.
    Edited by: Frank Kulash on Mar 11, 2009 4:52 PM

  • How do i put tv programmes and videos from itunes to another iphone, without having to delete all data on the phone and replacing it with my library? i switched the 'sync only ticked songs and videos box' yet it still wont let me transfer videos from my i

    How do i put tv programmes and videos from itunes to another iphone, without having to delete all data on the phone and replacing it with my library? i switched the 'sync only ticked songs and videos' yet it still wont let me transfer videos from my itunes onto my new phone, any ideas??

    Copy the entire itunes folder from the old computer to the new computer.

  • Calculated formula for replacing a comma with a Semicolon in a text field

    I need help replacing a comma with a Semicolon in a text field.
    I have a field that has names separated by commas.  
    Ex: Dog, Cat, Bird, Horse, Eagle, Worm, Snake
    I would like a calculated column that converts the field into: Dog; Cat; Bird; Horse; Eagle; Worm; Snake
    I figured out the first three positions (Dog, Cat, Bird,) but I can't figure out the rest.
    Using the formula below.
    =REPLACE((REPLACE((REPLACE([Title],SEARCH(",",[Title]),"1"," ; ")),SEARCH(",",(REPLACE([Title],SEARCH(",",[Title]),"1"," ; "))),"1"," ; ")),SEARCH(",",(REPLACE((REPLACE([Title],SEARCH(",",[Title]),"1","
    ; ")),SEARCH(",",(REPLACE([Title],SEARCH(",",[Title]),"1"," ; "))),"1"," ; "))),"1"," ; ")
    Please help

    check the similar post
    http://social.technet.microsoft.com/Forums/windowsserver/en-US/66e2ae2a-4da9-4c58-a8bb-cf46b1bf448f/calculated-column-to-replace-commas?forum=sharepointgenerallegacy

  • Replacing csv commas with tabs

    Has anyone come accross a command, preferably in vi to replace comma's seperated fields with tab delimited fields? I know about the substitution command but as people who work with csv files might know that fields of data with commas in them have quotation marks around them, I need to keep these commas in the file.

    Not sure if I understand this 100%
    But if I do, then this should work:
    `fixcsv.py inputfile outputfile`
    Things that are quoted because they contain a comma will no longer be quoted since thats no longer the delimiter (tab is). Also, you can uncomment the commented out line to have every field surrounded in quotes.
    #!/usr/bin/python
    #fixcsv.py
    import csv
    import sys
    reader = csv.reader(open(sys.argv[1], "rb"))
    writer = csv.writer(open(sys.argv[2], "wb"), delimiter='\t')
    #uncomment next line if you want everything quoted
    #writer = csv.writer(open(sys.argv[2], "wb"), delimiter='\t', quoting=csv.QUOTE_ALL)
    writer.writerows(reader)
    Be sure to backup your data just in case.
    Last edited by sabooky (2007-06-06 05:00:14)

  • Replace each third comma with ||

    Hi All,
    My Requirement is like this:
    In a column i need to replace every third comma(,) with || symbol.
    eg:
    1,Animesh,1234,2,Tripathi,4321,3,Oracle,2345.....(and so on)
    Desired output:
    1,Animesh,1234||2,Tripathi,4321||3,Oracle,2345....Please help me out.
    Regards
    Animesh
    Edited by: Animesh Tripathi on Dec 11, 2012 2:22 AM

    Animesh Tripathi wrote:
    Hi LPS,
    Sorry for duplicating the post.
    The reason i duplicated this is because, earlier i did not get any proper answer for this and I thought of replicating this
    to another community.
    AnimeshHi Animesh,
    you have posted again the same question to have again the same exact answer.
    I have answered you previously and you seemed also satisfied in this thread: {message:id=10739356}:
    Animesh Tripathi wrote:
    Hi Alberto,
    That was what i exactly wanted.
    Thanks for the Help.
    Regards
    AnimeshWhy are you saying you did not get a proper answer?
    Did you face any problem with previous solution?
    Regards.
    Al

  • How do I set up itunes sync with outlook to "replace information on this iphone" only? I do not want to do a two way sync.

    I am tired of fighting sync incompatibilities between Outlook 2007 and I Tunes, and no longer want to do a two-way sync.
    I still want my Outlook contacts and calendar on my iPhone and use advanced setup in iTunes to "replace information on this iPhone" only.
    iTunes only offers the ability to do this on "the next sync only". Is there a way to set up iTunes to "replace information on this iPhone" every time I connect my phone?

    Hi there Greg,
    Welcome to Apple Support Communities.
    It sounds like you want to always replace content on your iPhone 5S with content from Outlook on your PC, to do this you’ll just have to Reset the Sync History in iTunes as shown below.
    Troubleshooting Sync Services on Windows with Microsoft Outlook 2003, Outlook 2007, or Outlook 2010 - Apple Support
    To reset sync history:
    Open iTunes.
    From the Edit menu, choose Preferences.
    Click the Devices tab.
    Click the Reset Sync History button.
    If the issue continues and you know all of the data is on the computer:
    Reset the Sync History again using the steps above.
    Select the device in iTunes and click the Info tab.
    Scroll down to the Advanced section, and under "Replace information on this iPhone/iPad/iPod touch" select Contacts or Calendars.
    Click Apply.
    Cheers,
    -Jason

Maybe you are looking for