cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
Choose Language Hide Translation Bar
fionaweston
Level III

How do I extract only the text that is between quotation marks

I have a column containing 1000's of Machine Error Codes which are typed in by an operator at the machine.

Most of the errors do not have quotation marks but for those that do I would like to be able to extract what is between the quotation marks.

For other special characters I can use the escape character but I'm having problems using this with the quotation marks.

Thanks in advance

Fiona

 

Example 1: *******The unit is giving a “no scanner connection” error. Unit is INOP.
Example 2: ********P1-“Waiting for system authentication”, unable to run ******* Area C
Example 3: *********Now reads “X-ray error"

1 ACCEPTED SOLUTION

Accepted Solutions
jthi
Super User

Re: How do I extract only the text that is between quotation marks

There seems to be at least three different kinds of quotes in the example dataset (“ " ”).

 

Example script here should handle at least all of those.

Names Default To Here(1);
dt = New Table("Error Codes Quotations",
	Add Rows(3),
	Compress File When Saved(1),
	New Column("Error Code",
		Character,
		"Nominal",
		Set Values(
			{
			" ****  The unit is giving a “no scanner connection” error.  Unit is INOP.",
			"P1-“Waiting for system authentication”, unable to run  ******* Area C",
			"Now reads “X-ray error\!""}
		)
	)
);

dt << New Column("BetweenQuotes_Regex", Character, Nominal, << Formula(
	Regex(:Error Code, "[“|\!"|'](.*?)[”|\!"|']");
));
dt << New Column("BetweenQuotes_Word", Character, Nominal, << Formula(
	Word(2, :Error Code, "”“\!"")
));
-Jarmo

View solution in original post

2 REPLIES 2
jthi
Super User

Re: How do I extract only the text that is between quotation marks

There seems to be at least three different kinds of quotes in the example dataset (“ " ”).

 

Example script here should handle at least all of those.

Names Default To Here(1);
dt = New Table("Error Codes Quotations",
	Add Rows(3),
	Compress File When Saved(1),
	New Column("Error Code",
		Character,
		"Nominal",
		Set Values(
			{
			" ****  The unit is giving a “no scanner connection” error.  Unit is INOP.",
			"P1-“Waiting for system authentication”, unable to run  ******* Area C",
			"Now reads “X-ray error\!""}
		)
	)
);

dt << New Column("BetweenQuotes_Regex", Character, Nominal, << Formula(
	Regex(:Error Code, "[“|\!"|'](.*?)[”|\!"|']");
));
dt << New Column("BetweenQuotes_Word", Character, Nominal, << Formula(
	Word(2, :Error Code, "”“\!"")
));
-Jarmo
fionaweston
Level III

Re: How do I extract only the text that is between quotation marks

Thank you. This works great!!