Search and replace all lines in a multiline string

Nick

I have a string with a large list with items named as follows:

str = "f05cmdi-test1-name1
f06dmdi-test2-name2";

So the first 4 characters are random characters. And I would like to have an output like this:

'mdi-test1-name1',
'mdi-test2-name2',

As you can see the first characters from the string needs to be replaced with a ' and every line needs to end with ',

How can I change the above string into the string below? I've tried for ours with 'strstr' and 'str_replace' but I can't get it working. It would save me a lot of time if I got it work.

Thanks for your help guys!

Toto

Here is a way to do the job:

$input = "f05cmdi-test1-name1
f05cmdi-test2-name2";

$result = preg_replace("/.{4}(\S+)/", "'$1',", $input);
echo $result;

Where \S stands for a NON space character.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Java

Search and replace in vim in specific lines

From Java

RegEx for multiline search and replace in SQL query code

From Dev

Search for a String, and retrieve all lines following it until another specific pattern

From Dev

Get all lines from multiline textbox

From Dev

Why does removal of empty lines from multiline string in PowerShell fail using Replace function?

From Dev

python re.search not working on multiline string

From Dev

Search and replace shell variable with multiline shell variable

From Dev

Search and Replace in string in D

From Dev

Notepad ++ Perform Search Replace On All Lines Except Last

From Dev

Replace multiline string in all files in terminal

From Dev

WebStorm 11 - multiline button for search/replace missing?

From Dev

Intellij Javascript multiline structural search and replace

From Dev

Search and replace the string

From Dev

Replace string with multiline file content

From Dev

Search for multiline String in a text file

From Dev

Replace string with multiline file content

From Dev

Replace multiline string with js

From Dev

Search and replace in string

From Dev

Python search and replace in a string

From Dev

Global multiline search & replace

From Dev

Search and Replace in string in D

From Dev

javascript replace multiline string with multiline string

From Dev

Multiline string replace inside markup tag

From Dev

Replace text in file with multiline string

From Dev

Find and replace string spanned multiline

From Dev

Replace a multiline string with pattern using sed command

From Dev

Replace a multiline string with the content of a file.txt

From Dev

Search and Replace ( multiple lines )

From Dev

Search and replace for a specific string in multiple lines of a text file in matlab

Related Related

  1. 1

    Search and replace in vim in specific lines

  2. 2

    RegEx for multiline search and replace in SQL query code

  3. 3

    Search for a String, and retrieve all lines following it until another specific pattern

  4. 4

    Get all lines from multiline textbox

  5. 5

    Why does removal of empty lines from multiline string in PowerShell fail using Replace function?

  6. 6

    python re.search not working on multiline string

  7. 7

    Search and replace shell variable with multiline shell variable

  8. 8

    Search and Replace in string in D

  9. 9

    Notepad ++ Perform Search Replace On All Lines Except Last

  10. 10

    Replace multiline string in all files in terminal

  11. 11

    WebStorm 11 - multiline button for search/replace missing?

  12. 12

    Intellij Javascript multiline structural search and replace

  13. 13

    Search and replace the string

  14. 14

    Replace string with multiline file content

  15. 15

    Search for multiline String in a text file

  16. 16

    Replace string with multiline file content

  17. 17

    Replace multiline string with js

  18. 18

    Search and replace in string

  19. 19

    Python search and replace in a string

  20. 20

    Global multiline search & replace

  21. 21

    Search and Replace in string in D

  22. 22

    javascript replace multiline string with multiline string

  23. 23

    Multiline string replace inside markup tag

  24. 24

    Replace text in file with multiline string

  25. 25

    Find and replace string spanned multiline

  26. 26

    Replace a multiline string with pattern using sed command

  27. 27

    Replace a multiline string with the content of a file.txt

  28. 28

    Search and Replace ( multiple lines )

  29. 29

    Search and replace for a specific string in multiple lines of a text file in matlab

HotTag

Archive