Skip to main content
added 4 characters in body
Source Link
kglr
  • 400.5k
  • 18
  • 488
  • 929
StringCases[text, x___ ~~ "entitle" ~~ y___ :> 
   StringTake[x, -4] ~~ "entitle" ~~ StringTake[y, 5]]

or

StringCases[text, Repeated[_, 4] ~~ "entitle" ~~ Repeated[_, 5]]

Generalizing:

paddedString1[text_, string_, left_, right_] := 
 StringCases[text,  x___ ~~ string ~~ y___ :> 
  StringTake[x, -left] ~~ string ~~ StringTake[y, right]]

and

paddedString2[text_, string_, left_, right_] := 
 StringCases[text, Repeated[_, left]{left}] ~~ string ~~ Repeated[_, right]]{right}]]
StringCases[text, x___ ~~ "entitle" ~~ y___ :> 
   StringTake[x, -4] ~~ "entitle" ~~ StringTake[y, 5]]

or

StringCases[text, Repeated[_, 4] ~~ "entitle" ~~ Repeated[_, 5]]

Generalizing:

paddedString1[text_, string_, left_, right_] := 
 StringCases[text,  x___ ~~ string ~~ y___ :> 
  StringTake[x, -left] ~~ string ~~ StringTake[y, right]]

and

paddedString2[text_, string_, left_, right_] := 
 StringCases[text, Repeated[_, left] ~~ string ~~ Repeated[_, right]]
StringCases[text, x___ ~~ "entitle" ~~ y___ :> 
   StringTake[x, -4] ~~ "entitle" ~~ StringTake[y, 5]]

or

StringCases[text, Repeated[_, 4] ~~ "entitle" ~~ Repeated[_, 5]]

Generalizing:

paddedString1[text_, string_, left_, right_] := 
 StringCases[text,  x___ ~~ string ~~ y___ :> 
  StringTake[x, -left] ~~ string ~~ StringTake[y, right]]

and

paddedString2[text_, string_, left_, right_] := 
 StringCases[text, Repeated[_, {left}] ~~ string ~~ Repeated[_, {right}]]
added 336 characters in body
Source Link
kglr
  • 400.5k
  • 18
  • 488
  • 929
StringCases[text, x___ ~~ "entitle" ~~ y___ :> 
   StringTake[x, -4] ~~ "entitle" ~~ StringTake[y, 5]]

or

StringCases[text, Repeated[_, 4] ~~ "entitle" ~~ Repeated[_, 5]]

Generalizing:

paddedString1[text_, string_, left_, right_] := 
 StringCases[text,  x___ ~~ string ~~ y___ :> 
  StringTake[x, -left] ~~ string ~~ StringTake[y, right]]

and

paddedString2[text_, string_, left_, right_] := 
 StringCases[text, Repeated[_, left] ~~ string ~~ Repeated[_, right]]
StringCases[text, x___ ~~ "entitle" ~~ y___ :> 
   StringTake[x, -4] ~~ "entitle" ~~ StringTake[y, 5]]

or

StringCases[text, Repeated[_, 4] ~~ "entitle" ~~ Repeated[_, 5]]
StringCases[text, x___ ~~ "entitle" ~~ y___ :> 
   StringTake[x, -4] ~~ "entitle" ~~ StringTake[y, 5]]

or

StringCases[text, Repeated[_, 4] ~~ "entitle" ~~ Repeated[_, 5]]

Generalizing:

paddedString1[text_, string_, left_, right_] := 
 StringCases[text,  x___ ~~ string ~~ y___ :> 
  StringTake[x, -left] ~~ string ~~ StringTake[y, right]]

and

paddedString2[text_, string_, left_, right_] := 
 StringCases[text, Repeated[_, left] ~~ string ~~ Repeated[_, right]]
added 87 characters in body; deleted 4 characters in body; deleted 2 characters in body
Source Link
kglr
  • 400.5k
  • 18
  • 488
  • 929
 StringCases[text, x___ ~~ "entitle" ~~ y___ :> 
   StringTake[x, -4] ~~ "entitle" ~~ StringTake[y, 5]]

or

StringCases[text, Repeated[_, 4] ~~ "entitle" ~~ Repeated[_, 5]]
 StringCases[text, x___ ~~ "entitle" ~~ y___ :> 
   StringTake[x, -4] ~~ "entitle" ~~ StringTake[y, 5]]
StringCases[text, x___ ~~ "entitle" ~~ y___ :> 
   StringTake[x, -4] ~~ "entitle" ~~ StringTake[y, 5]]

or

StringCases[text, Repeated[_, 4] ~~ "entitle" ~~ Repeated[_, 5]]
Source Link
kglr
  • 400.5k
  • 18
  • 488
  • 929
Loading