Replace a string using regular expression from powershell

I want to replace the following:
'browserName': 'firefox'
with :
'browserName': 'chrome'
then I tried this:
(get-content $conffile) -replace "^('browserName': ')\S+","browserName': 'chrome' |set-content $conffile
But nothing happened.
Could someboby tell me how to write the regular expression here? Thanks a lot.

Second person today with the same question.
get-content $conffile |%{$_ -replace "'browserName':\s+'firefox'","'browserName': 'chrome'"  | set-content $conffile
\_(ツ)_/

Similar Messages

  • Format string using Regular Expression

    Input string output format...
    SELECT q'<select ab_c "ABC", efg "EFG" from dual>' str FROM DUAL
    Output:
    STR                                 
    select ab_c "ABC", efg "EFG" from dual
    Required output format using regular expression...
    STR                                 
    select 'ab_c' "ABC", 'efg' "EFG" from dual

    Regular expressions have many limitations as parsing tools, and you didn't specify the rules you wanted. This expression puts quotes around the non blank string before a quoted string:
    SELECT regexp_replace(q'<select ab_c "ABC", efg "EFG" from dual>',
                          '([^" ]+)( +"[^ ]*")' , '''\1''\2' ) str FROM DUAL;
    STR
    select 'ab_c' "ABC", 'efg' "EFG" from dual
    {code}
    It is not robust - a missing " will confuse it, and you should be using bind variables anyway.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               

  • Filter String using Regular Expression

    Hello,
    I have an application that monitors serial communication between a PC and device.  The message protocol is a byte stream that I convert to a string to parse into pretty messages.  The start of the string is always "10 02", but if the string is preceded with another "10" like this "10 10 02" it is part of a message.  I've been trying to use a regular expression with the Search and Replace VI.  My regex is "[^10]\s10\s02" which almost works but it cuts off part of the message:
    Before:
    10 03 10 02
    After:
    10 0   <= missing the "3"
    10 02
    Here's what I'm doing:
    Any ideas on what I'm missing?  I've attached a simple example.
    Thanks
    Message Edited by Derek Price on 02-14-2008 08:37 PM
    Attachments:
    Filter Beginning Message1.vi ‏14 KB
    FilterMessageRegex1.png ‏7 KB

    Try this approach.
    Do search and replace on '10\s02' and replace with '\r\n10\s20'
    Then do another search and replace on '10\r\n\10\s20'  with '10\s10\s20'
    See attached.
    Randall Pursley
    Attachments:
    Message Filter.PNG ‏18 KB

  • Spliting a large string using regular expression which contain special char

    I have huge sting(xml) containing normal character a-z,A-Z and 0-9 as well as special char( <,>,?,&,',",;,/ etc.)
    I need to split this sting where it ends with </document>
    for e.g.
    Original String:
    <document>
    <item>sdf</item>
    <item><text>sd</text</item>
    </document>
    <document>hi</document>
    The above sting has to be splited in to two parts since it is having two document tag.
    Can any body help me to resolve this issue. I can use StringTokenizer,String split method or Regular expression api too.

    manas589 wrote:
    I used DOM and sax parser and got few exception. Again i don't have right to change xml. so i thought to go with RegularExpression or some other way where i can do my job.If the file actually comes in lines like what you posted, you should just be able to compare the contents of each line to see if it contains "</document>" or whatever you're looking for. I wouldn't use regex unless I needed another problem.
    I got excpetion like: Caused by: org.xml.sax.SAXParseException: The entity "nbsp" was referenced, but not declared.
         at org.apache.xerces.util.ErrorHandlerWrapper.createSAXParseException(Unknown Source)
         at org.apache.xerces.util.ErrorHandlerWrapper.fatalError(Unknown Source)
         at org.apache.xerces.impl.XMLErrorReporter.reportError(Unknown Source)So then it isn't even XML.
    Edit: sorry, I just realized why you're considering all of these heavy-duty ideas. It's just that you don't know how to break the string into lines. You do it like this:
    BufferedReader  br = new BufferedReader(new StringReader(theNotXMLString));

  • How to Capture Multiple Line String using Regular Expression?

    Hi, 
    I have a simple program like this:
    What I want to accomplish is to capture everything between >>start and >>end using a single Match Regular Expression node. It seems that setting multiple? to True or False does not help.
    I am using LabVIEW 2012.
    If it is impossible to capture it using a single node, that is fine. But I want to make sure that I can make full use of this node without combining serveral others.
    Thank you!
    TailOfGon
    Certified LabVIEW Architect 2013
    Solved!
    Go to Solution.

    Thank you for the fast response! Your solution worked in the example case
    After I saw your post, I was finally able to step forward. But I still wanted to make use of dot notation due to the limitation of characters that match with \w. 
    I made some more modification to your regular expression then now it seems working for all characters:
    >>start((?:\s|.)*)>>end
    Thanks!
    TailOfGon
    Certified LabVIEW Architect 2013

  • Dumbfounded by Scanner processing String using regular expression

    I was reading Bruce Eckel's book when I came across something interesting: extending Scanner with regular expressions. Unfortunately, I was confronted with an issue that doesn't make much sense to me: if the String that I am scanning contains a hyphen, the Scanner doesn't produce anything. As soon as I take it out, it all works like a charm. Here is my example:
    import java.util.Scanner;
    import java.util.regex.*;
    public class StringScan {
    public static void main (String [] args){
         String input = "there's one caveat when scanning with regular expressions";
         Scanner scanner = new Scanner (input);
         String pattern = "[a-z]\\w+";
         while (scanner.hasNext(pattern)){
              scanner.next(pattern);
              MatchResult match = scanner.match();
              String output = match.group();
              System.out.println(output);
    }What could be the reason? I imagined it could be because the hyphen for some reason gets given a special meaning but when I tried escaping it, it still didn't work.

    Thanks for your prompt reply.
    I have figured out what was wrong with my code, by the way. Since a single quote is not a word character, it does not match w+. And as the very first input token does not match, the scanner stops immediately. I rewrote my regex to "[a-z].*" and now it does work.

  • Getting non numeric strings using regular expression

    Hi Guys ,
    I  want to get list of string values in table which contains no numeric values  .....
    I have a   string column name A and table name B  .
    I have written following code , but it seems it is incorrect  .
    Plz help me out  .....
    SELECT
    A FROM
    B
    WHERE
    regexp_like(A, '([^[:digit:]])'
    Thanks in advance ....

    96097f0e-f165-463a-a0a2-3d15214c8a3d wrote:
    Hi Guys ,
    I  want to get list of string values in table which contains no numeric values  .....
    I have a   string column name A and table name B  .
    I have written following code , but it seems it is incorrect  .
    Plz help me out  .....
    SELECT
    A FROM
    B
    WHERE
    regexp_like(A, '([^[:digit:]])'
    Thanks in advance ....
    That will give you every one that has at least one non-numeric character, if you want ones which contain no numeric characters then it should be
    regexp_like(A,'^[^0-9]*$')

  • Filter Strings using regular expressions

    Requirements.
    1.I have a table with different names.
    2.I input a word(string) through a text box.
    3.I filter table using the input string through text box using the code
    ((DefaultRowSorter)table_customer.getRowSorter()).setRowFilter(RowFilter.regexFilter(regex, indices));
    4.regex is obtained as follows.
    String regex = "";
    String text = txtFilterText.getText();
    regex = "^(?i)"text".*"; //for starts with filter
    regex = "." + text + ".";//for contains filter
    regex = "(?i)["text".*]";//for doesnt start with filter
    regex =".*(?i)"text"$";//for end with filter
    I need help for doesnt contain and doesnt end with filters.Plz help me out..
    Anees

    h2. {color:ff0000}Double post{color}
    Reply here: http://forum.java.sun.com/thread.jspa?threadID=5231406

  • Using Regular Expressions to replace Quotes in Strings

    I am writing a program that generates Java files and there are Strings that are used that contain Quotes. I want to use regular expressions to replace " with \" when it is written to the file. The code I was trying to use was:
    String temp = "\"Hello\" i am a \"variable\"";
    temp = temp.replaceAll("\"","\\\\\"");
    however, this does not work and when i print out the code to the file the resulting code appears as:
    String someVar = ""Hello" i am a "variable"";
    and not as:
    String someVar = "\"Hello\" i am a \"variable\"";
    I am assumming my regular expression is wrong. If it is, could someone explain to me how to fix it so that it will work?
    Thanks in advance.

    Thanks, appearently I'm just doing something weird that I just need to look at a little bit harder.

  • Remove regular expression from a string

    Hello,
    I have a string like this
    @1test;'"{input+
    Please help me to remove special characters from the string.

A: remove regular expression from a string

Hi Krishna,
DATA : str TYPE STRING VALUE '@1test;"{}]input+',
            char,
            length TYPE i,
            index TYPE i.
length = STRLEN( str ).
WHILE length > index.
  char = str+index(1).
  WRITE char.
  if char CA '+-*/!`@#$%^&()_=[]{};'.               " Add/Remove here to include numbers
    REPLACE ALL OCCURRENCES OF char in str WITH ''.
    REPLACE ALL OCCURRENCES OF '"' in str WITH ''.  " characters "{}[] are not comparable
    REPLACE ALL OCCURRENCES OF '{' in str WITH ''.
    REPLACE ALL OCCURRENCES OF '}' in str WITH ''.
    REPLACE ALL OCCURRENCES OF '[' in str WITH ''.
    REPLACE ALL OCCURRENCES OF ']' in str WITH ''.
    length = STRLEN( str ).
    ENDIF.
  add 1 to index.
ENDWHILE.
WRITE str.
Add or remove special char from '+-*/!`@#$%^&()_=[]{};' in if part as per your requirement.
Hope it meets your requirement.
Do not forget to mark helpful/correct if ma answer is useful .
Thanks,
Karthik

Hi Krishna,
DATA : str TYPE STRING VALUE '@1test;"{}]input+',
            char,
            length TYPE i,
            index TYPE i.
length = STRLEN( str ).
WHILE length > index.
  char = str+index(1).
  WRITE char.
  if char CA '+-*/!`@#$%^&()_=[]{};'.               " Add/Remove here to include numbers
    REPLACE ALL OCCURRENCES OF char in str WITH ''.
    REPLACE ALL OCCURRENCES OF '"' in str WITH ''.  " characters "{}[] are not comparable
    REPLACE ALL OCCURRENCES OF '{' in str WITH ''.
    REPLACE ALL OCCURRENCES OF '}' in str WITH ''.
    REPLACE ALL OCCURRENCES OF '[' in str WITH ''.
    REPLACE ALL OCCURRENCES OF ']' in str WITH ''.
    length = STRLEN( str ).
    ENDIF.
  add 1 to index.
ENDWHILE.
WRITE str.
Add or remove special char from '+-*/!`@#$%^&()_=[]{};' in if part as per your requirement.
Hope it meets your requirement.
Do not forget to mark helpful/correct if ma answer is useful .
Thanks,
Karthik

  • Replace string with regular expression

    I am new to the regular expression. I am just trying to remove double quotes from a string.
    My sample string is sql statement(SELECT "SCHEMA"."TABLE1"."COLUMN1", "SCHEMA"."TABLE1"."COLUMN2" FROM "SCHEMA"."TABLE1", "SCHEMA"."TABLE2" WHERE "SCHEMA"."TABLE1"."COLUMN1" = "SCHEMA"."TABLE2"."COLUMN1" );
    This is what I came up with.
    String s = query.replaceAll("\\.\"", ".").replaceAll("\"\\.", ".").replaceAll("\\s\"", " ").replaceAll("\\s\"", " ").replaceAll("\",", ",").replaceAll("\"\\s", " ");
    But I want to optimize this line.
    Could anybody tell me how to call replaceAll once with using regular expression instead of calling replaceAll multiple times? Some table or column names can have double quotes, so I want to remove the double quotes without replacing the double quotes which is part of the table or column name.
    I'd appreciated it.

    caesarkim1 wrote:
    I am new to the regular expression. I am just trying to remove double quotes from a string.
    My sample string is sql statement(SELECT "SCHEMA"."TABLE1"."COLUMN1", "SCHEMA"."TABLE1"."COLUMN2" FROM "SCHEMA"."TABLE1", "SCHEMA"."TABLE2" WHERE "SCHEMA"."TABLE1"."COLUMN1" = "SCHEMA"."TABLE2"."COLUMN1" );
    This is what I came up with.
    String s = query.replaceAll("\\.\"", ".").replaceAll("\"\\.", ".").replaceAll("\\s\"", " ").replaceAll("\\s\"", " ").replaceAll("\",", ",").replaceAll("\"\\s", " ");
    ...Note that the following two lines are equivalent:
    s = s.replaceAll("a","").replaceAll("b","");
    s = s.replaceAll("a|b","");

  • Changeparticular characters in a string by using regular expressions ...

    Hello Everyone,
    I am trying to write a function by using oracles regular expression function REGEXP_REPLACE but I could not succed till now.
    My problem as follows, I have a text in a column for example let say 'sdfsdf Sdfdfs Sdfd' I want replace all s and S characters with X and make the text look like 'XdfXdf XdfdfX Xdfd'.
    Is it possible by using regular expressions in oracle ?
    Can you give me some clues ?
    Thank you

    SSU wrote:
    Hello Everyone,
    I am trying to write a function by using oracles regular expression function REGEXP_REPLACE but I could not succed till now.
    My problem as follows, I have a text in a column for example let say 'sdfsdf Sdfdfs Sdfd' I want replace all s and S characters with X and make the text look like 'XdfXdf XdfdfX Xdfd'.
    Is it possible by using regular expressions in oracle ?
    Can you give me some clues ?
    Thank you
    SQL> SELECT
      2  regexp_replace('sdfsdf Sdfdfs Sdfd','s|S','X') from dual;
    REGEXP_REPLACE('SD
    XdfXdf XdfdfX XdfdRegards,
    Achyut

  • String extract using regular expression

    Hi
    I have text like this "<a>45</a><ct>Hi</ct><R>45 85</R><H>Here</H>" .I want to extract using regular expression or any techniques the text between <R> and </R> also need to replace the space with pipe between 45 and 85 like "45|85"
    Edited by: vishnu prakash on Mar 2, 2012 4:42 AM

    Hi,
    Here's one way:
    REPLACE ( REGEXP_REPLACE ( txt
                    , '.*<R>(.*)</R>.*'
                    , '\1'
         , '|'
         )This assumes there is only one <R> tag in txt.
    Always say which version of Oracle you're using. The expression above will work in Oralce 10 and up, but starting in Oracle 11 you can use REGEXP_SUBSTR rather than the less intuitive REGEXP_REPLACE.
    Edited by: Frank Kulash on Mar 2, 2012 7:48 AM

  • Find/Replace Using Regular Expressions

    Can someone help me with this...I am using Regular expressions to
    FIND:
    http.*lid=([^&"]*)[^"]*
    REPLACE:
    $set(\1,ID_id,code)$
    So that in the following it will change this:
    a href="http://www.test.com/shc/s/home_10153_12605?lid=Search" rilt="Search"
    To this:
    a href="$set(Search,ID_id,code)$" rilt="Search
    Those expressions  work in Notepad++ but when i use dreamweaver it just replaces the http... with "$set(\1,ID_id,code)$" and doesnt reference the "search"
    Any help?
    Thanks

    Let me begin by saying I'm a complete idiot with DW's Reg Ex.   I use Search Specific Tag whenever possible.  See screenshot below.
    Try this on your Current Document to see if it works. Then make a back-up copy of site before attempting it on Entire Local Site as you cannot "Undo" this process.
    Good luck,
    Nancy O.

  • Using regular expressions to get a customized output

    Hi,
    I have a string/varchar variable with the data ',a,b,c,' in it.
    I want the display as follows:
    a
    b
    c
    I would like to get the similar output using regular expressions.
    How do I get this output using REGEXP_REPLACE or REGEXP_SUBSTR?
    Please do the needful.
    Thanks & Regards,
    Rakshit

    I remember that, however if we look closer, that one has a little flaw: The 2nd row should be null, because ",," indicates an empy field. The MODEL clause solution works just fine in this case:
    with t as (select 'aaaa,,bbbb,cccc,dddd,eeee,ffff' col1 from dual)
    -- end of sample data
    SELECT col_new
      FROM t
    MODEL
       PARTITION BY (ROWNUM rn)
       DIMENSION BY (0 dim)
       MEASURES(col1, col1 col_new)
       RULES ITERATE(99) UNTIL (ITERATION_NUMBER = LENGTH(REGEXP_REPLACE(col1[0], '[^,]')))
                    (col_new[ITERATION_NUMBER] = REPLACE(REGEXP_SUBSTR(col1[0], '(^|,)[^,]*', 1, ITERATION_NUMBER+1), ','))
    COL_NEW                                                                                                                                                                  
    aaaa                                                                                                                                                                     
    bbbb                                                                                                                                                                     
    cccc                                                                                                                                                                     
    dddd                                                                                                                                                                     
    eeee
    ffff
    7 Zeilen ausgewählt.Update: I had this nagging feeling that I missed something, and there it was. If you want to see what the problem with my solution is, change the example to
    with t as (select ',aaaa,,bbbb,cccc,dddd,eeee,ffff' col1 from dual)So I went back and tried to fix BlueShadows approach. Here it is:
    with t as (select 'aaaa,,bbbb,cccc,dddd,eeee,ffff' txt from dual)
    -- end of sample data
    SELECT REPLACE(REGEXP_SUBSTR(',' || txt, ',[^,]*', 1, level), ',') col_new
      FROM t
      CONNECT BY level <= length(regexp_replace(txt,'[^,]*'))+1
    ;C.

  • Maybe you are looking for