Skip to main content
deleted 1 character in body
Source Link
Alexey Popkov
  • 62.3k
  • 7
  • 154
  • 375

I actually deal with the problem of finding quotations (i.e. "this is a quotation") in larger texts of different languages, mostly German and English. Unfortunately there are several ways to fill text in quotation marks (marks differ in various languages). I tried StringCases, but this did not work as expected:

test = "This is a „real“ test, even wit a \„really longer“ citation!"

„really longer“ citation!"

then:

StringCases[test, "„" ~~ __ ~~ "“"]
(* {"„real“ test, even wit a „really longer\
“"} *)

which is correct, but not what I intended. I also tried with RegularExpressionbut but could not get it to work as expected, so I got back to my "handmade" StringPosition which gave immediate success ;-)

pos = StringPosition[test, {"„", "“"}]

and

Partition[First /@ pos, 2]

finally:

StringTake[test, %]

This works, but I think this should be no problem with a RegularExpression or StringCases, only, ... I could not get it to work. Can anyone give me a hint (maybe it is obvious - but I do not see it)?

I actually deal with the problem of finding quotations (i.e. "this is a quotation") in larger texts of different languages, mostly German and English. Unfortunately there are several ways to fill text in quotation marks (marks differ in various languages). I tried StringCases, but this did not work as expected:

test = "This is a „real“ test, even wit a \

„really longer“ citation!"

then:

StringCases[test, "„" ~~ __ ~~ "“"]
(* {"„real“ test, even wit a „really longer\
“"} *)

which is correct, but not what I intended. I also tried with RegularExpressionbut could not get it to work as expected, so I got back to my "handmade" StringPosition which gave immediate success ;-)

pos = StringPosition[test, {"„", "“"}]

and

Partition[First /@ pos, 2]

finally:

StringTake[test, %]

This works, but I think this should be no problem with a RegularExpression or StringCases, only, ... I could not get it to work. Can anyone give me a hint (maybe it is obvious - but I do not see it)

I actually deal with the problem of finding quotations (i.e. "this is a quotation") in larger texts of different languages, mostly German and English. Unfortunately there are several ways to fill text in quotation marks (marks differ in various languages). I tried StringCases, but this did not work as expected:

test = "This is a „real“ test, even wit a „really longer“ citation!"

then:

StringCases[test, "„" ~~ __ ~~ "“"]
(* {"„real“ test, even wit a „really longer\
“"} *)

which is correct, but not what I intended. I also tried with RegularExpression but could not get it to work as expected, so I got back to my "handmade" StringPosition which gave immediate success ;-)

pos = StringPosition[test, {"„", "“"}]

and

Partition[First /@ pos, 2]

finally:

StringTake[test, %]

This works, but I think this should be no problem with a RegularExpression or StringCases, only, ... I could not get it to work. Can anyone give me a hint (maybe it is obvious - but I do not see it)?

deleted 132 characters in body
Source Link
LCarvalho
  • 9.3k
  • 5
  • 40
  • 97

I actually deal with the problem of finding quotations (i.e. "this is a quotation") in larger texts of different languages, mostly German and English. Unfortunately there are several ways to fill text in quotation marks (marks differ in various languages). I tried StringCases, but this did not work as expected:

test = "This is a „real\[OpenCurlyDoubleQuote]„real“ test, even wit a \

„really longer[OpenCurlyDoubleQuote]longer“ citation!"

then:

StringCases[test, "„" ~~ __ ~~ "\[OpenCurlyDoubleQuote]"]"“"]
(* {"„real\[OpenCurlyDoubleQuote]"„real“ test, even wit a „really longer\
\[OpenCurlyDoubleQuote]"“"} *)

which is correct, but not what I intended. I also tried with RegularExpressionbut could not get it to work as expected, so I got back to my "handmade" StringPosition which gave immediate success ;-)

pos = StringPosition[test, {"„", "\[OpenCurlyDoubleQuote]""“"}]

and

Partition[First /@ pos, 2]

finally:

StringTake[test, %]

This works, but I think this should be no problem with a RegularExpression or StringCases, only, ... I could not get it to work. Can anyone give me a hint (maybe it is obvious - but I do not see it)

I actually deal with the problem of finding quotations (i.e. "this is a quotation") in larger texts of different languages, mostly German and English. Unfortunately there are several ways to fill text in quotation marks (marks differ in various languages). I tried StringCases, but this did not work as expected:

test = "This is a „real\[OpenCurlyDoubleQuote] test, even wit a \

„really longer[OpenCurlyDoubleQuote] citation!"

then:

StringCases[test, "„" ~~ __ ~~ "\[OpenCurlyDoubleQuote]"]
(* {"„real\[OpenCurlyDoubleQuote] test, even wit a „really longer\
\[OpenCurlyDoubleQuote]"} *)

which is correct, but not what I intended. I also tried with RegularExpressionbut could not get it to work as expected, so I got back to my "handmade" StringPosition which gave immediate success ;-)

pos = StringPosition[test, {"„", "\[OpenCurlyDoubleQuote]"}]

and

Partition[First /@ pos, 2]

finally:

StringTake[test, %]

This works, but I think this should be no problem with a RegularExpression or StringCases, only, ... I could not get it to work. Can anyone give me a hint (maybe it is obvious - but I do not see it)

I actually deal with the problem of finding quotations (i.e. "this is a quotation") in larger texts of different languages, mostly German and English. Unfortunately there are several ways to fill text in quotation marks (marks differ in various languages). I tried StringCases, but this did not work as expected:

test = "This is a „real“ test, even wit a \

„really longer“ citation!"

then:

StringCases[test, "„" ~~ __ ~~ "“"]
(* {"„real“ test, even wit a „really longer\
“"} *)

which is correct, but not what I intended. I also tried with RegularExpressionbut could not get it to work as expected, so I got back to my "handmade" StringPosition which gave immediate success ;-)

pos = StringPosition[test, {"„", "“"}]

and

Partition[First /@ pos, 2]

finally:

StringTake[test, %]

This works, but I think this should be no problem with a RegularExpression or StringCases, only, ... I could not get it to work. Can anyone give me a hint (maybe it is obvious - but I do not see it)

Tweeted twitter.com/StackMma/status/676061599128494081
Source Link
mgamer
  • 5.6k
  • 20
  • 27

Finding quotations in a text

I actually deal with the problem of finding quotations (i.e. "this is a quotation") in larger texts of different languages, mostly German and English. Unfortunately there are several ways to fill text in quotation marks (marks differ in various languages). I tried StringCases, but this did not work as expected:

test = "This is a „real\[OpenCurlyDoubleQuote] test, even wit a \

„really longer[OpenCurlyDoubleQuote] citation!"

then:

StringCases[test, "„" ~~ __ ~~ "\[OpenCurlyDoubleQuote]"]
(* {"„real\[OpenCurlyDoubleQuote] test, even wit a „really longer\
\[OpenCurlyDoubleQuote]"} *)

which is correct, but not what I intended. I also tried with RegularExpressionbut could not get it to work as expected, so I got back to my "handmade" StringPosition which gave immediate success ;-)

pos = StringPosition[test, {"„", "\[OpenCurlyDoubleQuote]"}]

and

Partition[First /@ pos, 2]

finally:

StringTake[test, %]

This works, but I think this should be no problem with a RegularExpression or StringCases, only, ... I could not get it to work. Can anyone give me a hint (maybe it is obvious - but I do not see it)