WolframLang: String Replace

By Xah Lee. Date: .

search, test, pattern matching

These functions take a String pattern (regex) .

StringStartsQ
StringStartsQ
StringEndsQ
StringEndsQ
StringMatchQ
StringMatchQ
StringContainsQ
StringContainsQ[ "some thing", "th" ]
StringContainsQ
StringFreeQ
StringFreeQ
StringPosition
StringPosition
StringCount
Count occurance StringCount

Get Substring by Pattern

StringCases
Get substring, by String pattern (regex) . Return a List . StringCases
(* extract email address *)

x = "emails john@gmail.com and mary441@yahoo.com etc";

StringCases[
 x,
 RegularExpression[ "[a-z0-9]+@[a-z0-9]+\\.com" ],
 IgnoreCase -> True] === {"john@gmail.com", "mary441@yahoo.com"}

String Replace

StringReplace
replace string by String pattern (regex) . StringReplace
StringReplace[ "some dogs" , {"dog" -> "cat"}] === "some cats"
StringReplacePart
replace string by position. StringReplacePart
StringReplacePart[ "some dogs", "cat", {6, 8}] === "some cats"

WolframLang String

WolframLang in Depth

Basics

Comment, Print

String

Arithmetic

List

Expression, Atom, Head

Boolean

Conditional

Variable

Loop

Data Structure

Function

Pattern Matching

Advanced

Shell Tasks

Misc