<!--
{
  "availability" : [
    "iOS: 16.0.0 -",
    "iPadOS: 16.0.0 -",
    "macCatalyst: 16.0.0 -",
    "macOS: 13.0.0 -",
    "tvOS: 16.0.0 -",
    "visionOS: 1.0.0 -",
    "watchOS: 9.0.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "Swift",
  "identifier" : "/documentation/Swift/RegexComponent/anyOf(_:)-4xgea",
  "metadataVersion" : "0.1.0",
  "role" : "Type Method",
  "symbol" : {
    "kind" : "Type Method",
    "modules" : [
      "Swift"
    ],
    "preciseIdentifier" : "s:17_StringProcessing14RegexComponentP0C7BuilderAD14CharacterClassVRszrlE5anyOfyAFqd__STRd__SJ7ElementRtd__lFZ"
  },
  "title" : "anyOf(_:)"
}
-->

# anyOf(_:)

Returns a character class that matches any character in the given string
or sequence.

```
static func anyOf<S>(_ s: S) -> CharacterClass where S : Sequence, S.Element == Character
```

## Discussion

Calling this method with a group of characters is equivalent to listing
those characters in a custom character class in regex syntax. For example,
the two regexes in this example are equivalent:

```
let regex1 = /[abcd]+/
let regex2 = OneOrMore(.anyOf("abcd"))
```

---

Copyright &copy; 2026 Apple Inc. All rights reserved. | [Terms of Use](https://www.apple.com/legal/internet-services/terms/site.html) | [Privacy Policy](https://www.apple.com/privacy/privacy-policy)