Regex: Match any character (including whitespace) except a comma

regexsedstringstring-parsing

I would like to match any character and any whitespace except comma with regex. Only matching any character except comma gives me:

[^,]*

but I also want to match any whitespace characters, tabs, space, newline, etc. anywhere in the string.

EDIT:

This is using sed in vim via :%s/foo/bar/gc.

I want to find starting from func up until the comma, in the following example:

func("bla bla bla"
  "asdfasdfasdfasdfasdfasdf"
"asdfasdfasdf", "more strings")

I

Best Answer

To work with multiline in SED using RegEx, you should look at here.

EDIT:

In SED command, working with NewLine is a bit different. SED command support three patterns to manage multiline operations N, P and D. To see how it works see this(Working with Multiple Lines) explaination. Here these three operations discussed.

My guess is that N operator is the area of consideration that is missing from here. Addition of N operator will allows to sense \n in string.

An example from here:

Occasionally one wishes to use a new line character in a sed script. Well, this has some subtle issues here. If one wants to search for a new line, one has to use "\n." Here is an example where you search for a phrase, and delete the new line character after that phrase - joining two lines together.

(echo a;echo x;echo y) | sed '/x$/ { N s:x\n:x: }'

which generates

a xy

However, if you are inserting a new line, don't use "\n" - instead insert a literal new line character:

(echo a;echo x;echo y) | sed 's:x:X\ :'

generates

a X

y

Related Topic