221 references to RegexOptions
System.Text.RegularExpressions.Generator (221)
RegexGenerator.cs (3)
83RegexTree regexTree = RegexParser.Parse(method.Pattern, method.Options | RegexOptions.Compiled, method.Culture); // make sure Compiled is included to get all optimizations applied to it 193var emittedExpressions = new Dictionary<(string Pattern, RegexOptions Options, int? Timeout), RegexMethod>(); 373if (node.Kind is RegexNodeKind.Backreference && (node.Options & RegexOptions.IgnoreCase) != 0)
RegexGenerator.Emitter.cs (23)
89if (regexMethod.Options != RegexOptions.None) 753bool rtl = (rm.Options & RegexOptions.RightToLeft) != 0; 839RegexOptions options = rm.Options; 841bool rtl = (options & RegexOptions.RightToLeft) != 0; 1613RegexOptions options = rm.Options; 1826if ((node.Options & RegexOptions.RightToLeft) != 0 || 2215if ((node.Options & RegexOptions.ECMAScript) != 0) 2243if ((node.Options & RegexOptions.RightToLeft) == 0) 2733string startingPos = ReserveName((node.Options & RegexOptions.RightToLeft) != 0 ? "positivelookbehind_starting_pos" : "positivelookahead_starting_pos"); 2776string variablePrefix = (node.Options & RegexOptions.RightToLeft) != 0 ? "negativelookbehind_" : "negativelookahead_"; 2877if ((node.Options & RegexOptions.RightToLeft) != 0) 2941case RegexNodeKind.Multi when (node.Options & RegexOptions.RightToLeft) == 0: 3082if ((node.Options & RegexOptions.RightToLeft) == 0 && 3202bool rtl = (node.Options & RegexOptions.RightToLeft) != 0; 3285Debug.Assert((node.Options & RegexOptions.RightToLeft) == 0 || sliceStaticPos == 0); 3352EmitMultiCharString(node.Str, emitLengthCheck, clauseOnly: false, (node.Options & RegexOptions.RightToLeft) != 0); 3425bool rtl = (node.Options & RegexOptions.RightToLeft) != 0; 3635if ((node.Options & RegexOptions.RightToLeft) == 0) 4087bool rtl = (node.Options & RegexOptions.RightToLeft) != 0; 4223bool rtl = (node.Options & RegexOptions.RightToLeft) != 0; 4339bool rtl = (node.Options & RegexOptions.RightToLeft) != 0; 5504private static string Literal(RegexOptions options) 5537bool rtl = (node.Options & RegexOptions.RightToLeft) != 0;
RegexGenerator.Parser.cs (19)
141RegexOptions regexOptions = options is not null ? (RegexOptions)options : RegexOptions.None; 150RegexOptions regexOptionsWithPatternOptions; 160if ((regexOptionsWithPatternOptions & RegexOptions.IgnoreCase) != 0 && !string.IsNullOrEmpty(cultureName)) 162if ((regexOptions & RegexOptions.CultureInvariant) != 0) 179const RegexOptions SupportedOptions = 180RegexOptions.Compiled | 181RegexOptions.CultureInvariant | 182RegexOptions.ECMAScript | 183RegexOptions.ExplicitCapture | 184RegexOptions.IgnoreCase | 185RegexOptions.IgnorePatternWhitespace | 186RegexOptions.Multiline | 187RegexOptions.NonBacktracking | 188RegexOptions.RightToLeft | 189RegexOptions.Singleline; 252internal sealed record RegexPatternAndSyntax(RegexType DeclaringType, bool IsProperty, Location DiagnosticLocation, string MemberName, string Modifiers, bool NullableRegex, string Pattern, RegexOptions Options, int? MatchTimeout, CultureInfo Culture, CompilationData CompilationData); 255internal sealed record RegexMethod(RegexType DeclaringType, bool IsProperty, string MemberName, string Modifiers, bool NullableRegex, string Pattern, RegexOptions Options, int? MatchTimeout, RegexTree Tree, AnalysisResults Analysis, CompilationData CompilationData)
src\libraries\System.Text.RegularExpressions\src\System\Text\RegularExpressions\RegexCaseBehavior.cs (2)
9/// When a regular expression specifies the option <see cref="RegexOptions.IgnoreCase"/> then comparisons between the input and the 27/// specified <see cref="RegexOptions.CultureInvariant"/> or when the CurrentCulture is <see cref="CultureInfo.InvariantCulture"/>.
src\libraries\System.Text.RegularExpressions\src\System\Text\RegularExpressions\RegexFindOptimizations.cs (6)
18public static RegexFindOptimizations Create(RegexNode root, RegexOptions options) 22if ((options & RegexOptions.RightToLeft) == 0 && 46private RegexFindOptimizations(RegexNode root, RegexOptions options, bool isLeadingPartial) 48bool rightToLeft = (options & RegexOptions.RightToLeft) != 0; 114bool dfa = (options & RegexOptions.NonBacktracking) != 0; 115bool compiled = (options & RegexOptions.Compiled) != 0 && !dfa; // for now, we never generate code for NonBacktracking, so treat it as non-compiled
src\libraries\System.Text.RegularExpressions\src\System\Text\RegularExpressions\RegexNode.cs (53)
42public RegexOptions Options; 51public RegexNode(RegexNodeKind kind, RegexOptions options) 57public RegexNode(RegexNodeKind kind, RegexOptions options, char ch) 64public RegexNode(RegexNodeKind kind, RegexOptions options, string str) 71public RegexNode(RegexNodeKind kind, RegexOptions options, int m) 78public RegexNode(RegexNodeKind kind, RegexOptions options, int m, int n) 110public static RegexNode CreateOneWithCaseConversion(char ch, RegexOptions options, CultureInfo? culture, ref RegexCaseBehavior caseBehavior) 113if ((options & RegexOptions.IgnoreCase) != 0) 121return new RegexNode(RegexNodeKind.One, options & ~RegexOptions.IgnoreCase, ch); 127return new RegexNode(RegexNodeKind.Set, options & ~RegexOptions.IgnoreCase, stringSet); 137if ((Options & RegexOptions.RightToLeft) != 0 && 355Debug.Assert((node.Options & RegexOptions.IgnoreCase) == 0, $"{node.Kind} node should not have RegexOptions.IgnoreCase"); 379if ((rootNode.Options & (RegexOptions.RightToLeft | RegexOptions.NonBacktracking)) == 0) 454(Options & RegexOptions.NonBacktracking) != 0) 469bool rtl = (node.Options & RegexOptions.RightToLeft) != 0; 581Options &= ~RegexOptions.IgnoreCase; 652if ((Options & RegexOptions.NonBacktracking) != 0) 696if ((Options & RegexOptions.RightToLeft) == 0) 1071RegexOptions optionsLast = 0; 1072RegexOptions optionsAt; 1109optionsAt = at.Options & (RegexOptions.RightToLeft | RegexOptions.IgnoreCase); 1157if ((prev.Options & RegexOptions.IgnoreCase) != 0) 1159prev.Options &= ~RegexOptions.IgnoreCase; 1191if ((alternation.Options & RegexOptions.RightToLeft) != 0) 1339if ((alternation.Options & RegexOptions.RightToLeft) != 0) 1354RegexOptions startingNodeOptions = startingNode.Options; 1500Debug.Assert((Options & RegexOptions.RightToLeft) == 0); 1515Debug.Assert((Options & RegexOptions.RightToLeft) == 0); 1580if (node is not null && (node.Options & RegexOptions.RightToLeft) == 0) 1730RegexOptions optionsLast = 0; 1744((at.Options & RegexOptions.RightToLeft) == (Options & RegexOptions.RightToLeft))) 1765RegexOptions optionsAt = at.Options & (RegexOptions.RightToLeft | RegexOptions.IgnoreCase); 1782prev.Str = (optionsAt & RegexOptions.RightToLeft) == 0 ? 1891(nextNode.Options & RegexOptions.RightToLeft) == 0 && // RTL multi nodes don't have their text reversed, and it's not worth the code to optimize further 1992Debug.Assert((Options & RegexOptions.NonBacktracking) == 0, "Atomic groups aren't supported and don't help performance with NonBacktracking"); 2027(node.Options & RegexOptions.RightToLeft) != 0) 2219if (((Options & RegexOptions.RightToLeft) == 0 && IsZeroWidthAssertion(child.Kind)) || 2319if (condition.Kind == RegexNodeKind.PositiveLookaround && (condition.Options & RegexOptions.RightToLeft) == 0) 2378case RegexNodeKind.PositiveLookaround when (subsequent.Options & RegexOptions.RightToLeft) == 0: 2656if ((node.Options & RegexOptions.RightToLeft) != 0 || 3218if ((Options & RegexOptions.NonBacktracking) != 0) 3309if ((Options & RegexOptions.ExplicitCapture) != 0) sb.Append("-C"); 3310if ((Options & RegexOptions.IgnoreCase) != 0) sb.Append("-I"); 3311if ((Options & RegexOptions.RightToLeft) != 0) sb.Append("-L"); 3312if ((Options & RegexOptions.Multiline) != 0) sb.Append("-M"); 3313if ((Options & RegexOptions.Singleline) != 0) sb.Append("-S"); 3314if ((Options & RegexOptions.IgnorePatternWhitespace) != 0) sb.Append("-X"); 3315if ((Options & RegexOptions.ECMAScript) != 0) sb.Append("-E");
src\libraries\System.Text.RegularExpressions\src\System\Text\RegularExpressions\RegexNodeKind.cs (14)
18/// <summary>Anything other than a specific character, e.g. `.` when not in <see cref="RegexOptions.Singleline"/> mode, or `[^a]`.</summary> 35/// <summary>A loop around anything other than a specific character, e.g. `.*` when not in <see cref="RegexOptions.Singleline"/> mode, or `[^a]*`.</summary> 48/// <summary>A lazy loop around anything other than a specific character, e.g. `.*?` when not in <see cref="RegexOptions.Singleline"/> mode, or `[^a]*?`.</summary> 63/// <summary>An atomic loop around anything other than a specific character, e.g. `(?>.*)` when not in <see cref="RegexOptions.Singleline"/> mode.</summary> 80/// <summary>A beginning-of-line anchor, e.g. `^` in <see cref="RegexOptions.Multiline"/> mode.</summary> 82/// <summary>An end-of-line anchor, e.g. `$` in <see cref="RegexOptions.Multiline"/> mode.</summary> 88/// <summary>A word boundary anchor, e.g. `\b` in <see cref="RegexOptions.ECMAScript"/> mode.</summary> 90/// <summary>Not a word boundary anchor, e.g. `\B` in <see cref="RegexOptions.ECMAScript"/> mode..</summary> 92/// <summary>A beginning-of-string anchor, e.g. `\A`, or `^` when not in <see cref="RegexOptions.Multiline"/> mode.</summary> 96/// <summary>A end-of-string-or-before-ending-newline anchor, e.g. `\Z`, or `$` when not in <see cref="RegexOptions.Multiline"/> mode.</summary> 156/// A positive lookaround assertion: lookahead if <see cref="RegexOptions.RightToLeft"/> is not set and lookbehind if 157/// <see cref="RegexOptions.RightToLeft"/> is set, e.g. `(?=abc)` or `(?&lt;=abc)`.</summary> 161/// A negative lookaround assertion: lookahead if <see cref="RegexOptions.RightToLeft"/> is not set and lookbehind if 162/// <see cref="RegexOptions.RightToLeft"/> is set, e.g. `(?!abc)` or `(?&lt;!abc)`.</summary>
src\libraries\System.Text.RegularExpressions\src\System\Text\RegularExpressions\RegexParser.cs (71)
47private RegexOptions _options; 55private RegexParser(string pattern, RegexOptions options, CultureInfo culture, Hashtable caps, int capsize, Hashtable? capnames, Span<int> optionSpan) 85internal static CultureInfo GetTargetCulture(RegexOptions options) => 87(options & RegexOptions.CultureInvariant) != 0 ? CultureInfo.InvariantCulture : CultureInfo.CurrentCulture; 90public static RegexOptions ParseOptionsInPattern(string pattern, RegexOptions options) 98parser.CountCaptures(out RegexOptions foundOptionsInPattern); 103public static RegexTree Parse(string pattern, RegexOptions options, CultureInfo culture) 137public static RegexReplacement ParseReplacement(string pattern, RegexOptions options, Hashtable caps, int capsize, Hashtable capnames) 140CultureInfo culture = (options & RegexOptions.CultureInvariant) != 0 ? CultureInfo.InvariantCulture : CultureInfo.CurrentCulture; 223var parser = new RegexParser(input, RegexOptions.None, CultureInfo.InvariantCulture, new Hashtable(), 0, null, stackalloc int[OptionStackDefaultSize]); 257private void Reset(RegexOptions options) 277StartGroup(new RegexNode(RegexNodeKind.Capture, (_options & ~RegexOptions.IgnoreCase), 0, -1)); 290if ((_options & RegexOptions.IgnorePatternWhitespace) != 0) 346string setString = ScanCharClass((_options & RegexOptions.IgnoreCase) != 0, scanOnly: false)!.ToStringClass(); 347_unit = new RegexNode(RegexNodeKind.Set, _options & ~RegexOptions.IgnoreCase, setString); 376_options = (RegexOptions)_optionsStack.Pop(); 394_unit = new RegexNode((_options & RegexOptions.Multiline) != 0 ? RegexNodeKind.Bol : RegexNodeKind.Beginning, _options); 398_unit = new RegexNode((_options & RegexOptions.Multiline) != 0 ? RegexNodeKind.Eol : RegexNodeKind.EndZ, _options); 402_unit = (_options & RegexOptions.Singleline) != 0 ? 403new RegexNode(RegexNodeKind.Set, _options & ~RegexOptions.IgnoreCase, RegexCharClass.AnyClass) : 404new RegexNode(RegexNodeKind.Notone, _options & ~RegexOptions.IgnoreCase, '\n'); 571if ((_options & RegexOptions.ECMAScript) != 0 && _pattern[_pos] == ']') 591if ((_options & RegexOptions.ECMAScript) != 0 && _pos < _pattern.Length && _pattern[_pos] == ']') 649charClass!.AddDigit((_options & RegexOptions.ECMAScript) != 0, ch == 'D', _pattern, _pos); 661charClass!.AddSpace((_options & RegexOptions.ECMAScript) != 0, ch == 'S'); 674charClass!.AddWord((_options & RegexOptions.ECMAScript) != 0, ch == 'W'); 803if ((_options & RegexOptions.ExplicitCapture) != 0 || _ignoreNextParen) 835_options &= ~RegexOptions.RightToLeft; 841_options &= ~RegexOptions.RightToLeft; 869_options |= RegexOptions.RightToLeft; 880_options |= RegexOptions.RightToLeft; 1088if ((_options & RegexOptions.IgnorePatternWhitespace) != 0) 1096if ((_options & RegexOptions.IgnorePatternWhitespace) != 0 && _pos < _pattern.Length && _pattern[_pos] == '#') 1143new RegexNode(RegexNodeKind.Set, (_options & ~RegexOptions.IgnoreCase), (_options & RegexOptions.ECMAScript) != 0 ? RegexCharClass.ECMAWordClass : RegexCharClass.WordClass); 1148new RegexNode(RegexNodeKind.Set, (_options & ~RegexOptions.IgnoreCase), (_options & RegexOptions.ECMAScript) != 0 ? RegexCharClass.NotECMAWordClass : RegexCharClass.NotWordClass); 1153new RegexNode(RegexNodeKind.Set, (_options & ~RegexOptions.IgnoreCase), (_options & RegexOptions.ECMAScript) != 0 ? RegexCharClass.ECMASpaceClass : RegexCharClass.SpaceClass); 1158new RegexNode(RegexNodeKind.Set, (_options & ~RegexOptions.IgnoreCase), (_options & RegexOptions.ECMAScript) != 0 ? RegexCharClass.NotECMASpaceClass : RegexCharClass.NotSpaceClass); 1163new RegexNode(RegexNodeKind.Set, (_options & ~RegexOptions.IgnoreCase), (_options & RegexOptions.ECMAScript) != 0 ? RegexCharClass.ECMADigitClass : RegexCharClass.DigitClass); 1168new RegexNode(RegexNodeKind.Set, (_options & ~RegexOptions.IgnoreCase), (_options & RegexOptions.ECMAScript) != 0 ? RegexCharClass.NotECMADigitClass : RegexCharClass.NotDigitClass); 1179cc.AddCategoryFromName(ParseProperty(), ch != 'p', (_options & RegexOptions.IgnoreCase) != 0, _pattern, _pos); 1180if ((_options & RegexOptions.IgnoreCase) != 0) 1185return new RegexNode(RegexNodeKind.Set, (_options & ~RegexOptions.IgnoreCase), cc.ToStringClass()); 1189if (result != null && result.Kind == RegexNodeKind.Backreference && (result.Options & RegexOptions.IgnoreCase) != 0) 1259if ((_options & RegexOptions.ECMAScript) != 0) 1361if (!angled && (_options & RegexOptions.ECMAScript) != 0) 1490if ((_options & RegexOptions.ECMAScript) != 0 && i >= 0x20) 1594RegexOptions options = (char)(ch | 0x20) switch 1596'i' => RegexOptions.IgnoreCase, 1597'm' => RegexOptions.Multiline, 1598'n' => RegexOptions.ExplicitCapture, 1599's' => RegexOptions.Singleline, 1600'x' => RegexOptions.IgnorePatternWhitespace, 1601_ => RegexOptions.None, 1656if ((_options & RegexOptions.ECMAScript) == 0 && RegexCharClass.IsBoundaryWordChar(ch)) 1703'b' => (_options & RegexOptions.ECMAScript) != 0 ? RegexNodeKind.ECMABoundary : RegexNodeKind.Boundary, 1704'B' => (_options & RegexOptions.ECMAScript) != 0 ? RegexNodeKind.NonECMABoundary : RegexNodeKind.NonBoundary, 1715private void CountCaptures(out RegexOptions optionsFoundInPattern) 1718optionsFoundInPattern = RegexOptions.None; 1735if ((_options & RegexOptions.IgnorePatternWhitespace) != 0) 1749_options = (RegexOptions)_optionsStack.Pop(); 1820if ((_options & RegexOptions.ExplicitCapture) == 0 && !_ignoreNextParen) 2047_concatenation!.AddChild(RegexNode.CreateOneWithCaseConversion(_pattern[pos], isReplacement ? _options & ~RegexOptions.IgnoreCase : _options, _culture, ref _caseBehavior)); 2050case > 1 when (_options & RegexOptions.IgnoreCase) == 0 || isReplacement || !RegexCharClass.ParticipatesInCaseConversion(_pattern.AsSpan(pos, cch)): 2051_concatenation!.AddChild(new RegexNode(RegexNodeKind.Multi, _options & ~RegexOptions.IgnoreCase, _pattern.Substring(pos, cch)));
src\libraries\System.Text.RegularExpressions\src\System\Text\RegularExpressions\RegexPrefixAnalyzer.cs (8)
65(node.Options & RegexOptions.RightToLeft) != 0 || 358bool rtl = (node.Options & RegexOptions.RightToLeft) != 0; 593if ((node.Options & RegexOptions.RightToLeft) != 0) 1004bool firstChar = findFirst == ((node.Options & RegexOptions.RightToLeft) == 0); 1129if ((node.Options & RegexOptions.RightToLeft) != 0) 1272if ((node.Options & RegexOptions.RightToLeft) != 0) 1363case RegexNodeKind.PositiveLookaround when leading && (node.Options & RegexOptions.RightToLeft) == 0: 1389case RegexNodeKind.PositiveLookaround when ((node.Options | tmpChild.Options) & RegexOptions.RightToLeft) != 0:
src\libraries\System.Text.RegularExpressions\src\System\Text\RegularExpressions\RegexTree.cs (2)
17public readonly RegexOptions Options; 43internal RegexTree(RegexNode root, int captureCount, string[]? captureNames, Hashtable? captureNameToNumberMapping, Hashtable? captureNumberSparseMapping, RegexOptions options, CultureInfo? culture)
src\libraries\System.Text.RegularExpressions\src\System\Text\RegularExpressions\RegexTreeAnalyzer.cs (6)
27results._hasIgnoreCase |= (node.Options & RegexOptions.IgnoreCase) != 0; 28results._hasRightToLeft |= (node.Options & RegexOptions.RightToLeft) != 0; 161/// <summary>Whether any node has <see cref="RegexOptions.IgnoreCase"/> set.</summary> 163/// <summary>Whether any node has <see cref="RegexOptions.RightToLeft"/> set.</summary> 222/// <summary>Gets whether a node might have <see cref="RegexOptions.IgnoreCase"/> set.</summary> 230/// <summary>Gets whether a node might have <see cref="RegexOptions.RightToLeft"/> set.</summary>
UpgradeToGeneratedRegexAnalyzer.cs (4)
194_ = RegexParser.ParseOptionsInPattern((string)argument.Value.ConstantValue.Value!, RegexOptions.None); 215RegexOptions value = (RegexOptions)(int)argument.Value.ConstantValue.Value!; 216if ((value & RegexOptions.NonBacktracking) > 0)
UpgradeToGeneratedRegexCodeFixer.cs (10)
284RegexOptions regexOptions = regexOptionsValue is not null ? GetRegexOptionsFromArgument(operationArguments) : RegexOptions.None; 303if ((regexOptions & RegexOptions.IgnoreCase) != 0 && (regexOptions & RegexOptions.CultureInvariant) == 0) 365private static RegexOptions GetRegexOptionsFromArgument(ImmutableArray<IArgumentOperation> arguments) 370RegexOptions.None : 371(RegexOptions)(int)optionsArgument.Value.ConstantValue.Value!; 390string optionsLiteral = Literal(((RegexOptions)(int)argument.Value.ConstantValue.Value!).ToString()); 426return $"({nameof(RegexOptions)})({options})"; 433select $"{nameof(RegexOptions)}.{part.Trim()}");