---
title: "anyOf(_:)"
framework: swift
role: symbol
role_heading: Type Method
path: "swift/regexcomponent/anyof(_:)-4xgea"
---

# anyOf(_:)

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

## Declaration

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

## Discussion

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"))

## See Also

### Matching substring sequences

- [anyOf(_:)](swift/regexcomponent/anyof(_:)-3pexl.md)
- [any](swift/regexcomponent/any.md)
- [anyGraphemeCluster](swift/regexcomponent/anygraphemecluster.md)
- [anyNonNewline](swift/regexcomponent/anynonnewline.md)
- [digit](swift/regexcomponent/digit.md)
- [hexDigit](swift/regexcomponent/hexdigit.md)
- [word](swift/regexcomponent/word.md)
