String

extension String
  • Returns a new string where the first match is replaced with the template.

    You can use template variables like $ and $0 in the template. More info.

    import Regex
    
    "123🦄456".replacingFirstMatch(of: Regex(#"\d+"#), with: "")
    //=> "🦄456"
    

    Declaration

    Swift

    public func replacingFirstMatch(
    	of regex: Regex,
    	with template: String
    ) -> Self
  • Returns a new string where the first match is replaced with the template.

    You can use template variables like $ and $0 in the template. More info.

    import Regex
    
    "123🦄456".replacingFirstMatch(of: #"\d+"#, with: "")
    //=> "🦄456"
    

    Declaration

    Swift

    public func replacingFirstMatch(
    	of regexPattern: StaticString,
    	with template: String
    ) -> Self
  • Returns a new string where all matches are replaced with the template.

    You can use template variables like $ and $0 in the template. More info.

    import Regex
    
    "123🦄456".replacingAllMatches(of: Regex(#"\d+"#), with: "")
    //=> "🦄"
    

    Declaration

    Swift

    public func replacingAllMatches(
    	of regex: Regex,
    	with template: String,
    	options: Regex.MatchingOptions = []
    ) -> Self
  • Returns a new string where all matches are replaced with the template.

    You can use template variables like $ and $0 in the template. More info.

    import Regex
    
    "123🦄456".replacingAllMatches(of: #"\d+"#, with: "")
    //=> "🦄"
    

    Declaration

    Swift

    public func replacingAllMatches(
    	of regexPattern: StaticString,
    	with template: String,
    	options: Regex.MatchingOptions = []
    ) -> Self