public JoniRegexEngine(String regex, int flags) { this.regex = regex; byte[] b = Bytes.toBytes(regex); this.pattern = new Regex(b, 0, b.length, patternToJoniFlags(flags), encoding, Syntax.Java); }
Regex r = new Regex("YOURREGEX"); // search for a match within a string r.search("YOUR STRING YOUR STRING"); if(r.didMatch()){ // Prints "true" -- r.didMatch() is a boolean function // that tells us whether the last search was successful // in finding a pattern. // r.left() returns left String , string before the matched pattern int index = r.left().length(); }
Regex r = new Regex(@"^(\1.|^.)+$"); Console.WriteLine(r.IsMatch("aababc")); // True Console.WriteLine(r.IsMatch("1121231234")); // True Console.WriteLine(r.IsMatch("iLoveRegEx")); // False for (int n = 0; n <= 50; n++) { Match m = r.Match("".PadLeft(n)); if (m.Success) { Console.WriteLine("{0} = sum(1..{1})", n, m.Groups[1].Length); } } // 1 = sum(1..1) // 3 = sum(1..2) // 6 = sum(1..3) // 10 = sum(1..4) // 15 = sum(1..5) // 21 = sum(1..6) // 28 = sum(1..7) // 36 = sum(1..8) // 45 = sum(1..9)
public JONIPattern(String patternString, int flags, Encoding coding) { this.patternString = patternString; if (patternString != null) { byte[] bytes = patternString.getBytes(); pattern = new Regex(bytes, 0, bytes.length, flags, coding, Syntax.Java); } else { pattern = null; } }
Regex r = new Regex("=([^;]*);"); Match m = r.Match(yourData); while (m.Success) { string match = m.Groups[1]; // match should be the text between the '=' and the ';'. }
Regex r = new Regex( @"(?x) ^.{0,1}$ | ^(?: (?=(\2?)) (?=(\2\3|^.)) (?=(\1)) \2)+ . $ " ); for (int n = 0; n < 1000; n++) { if (r.IsMatch("".PadLeft(n))) { Console.Write("{0} ", n); } } // 0 1 2 3 5 8 13 21 34 55 89 144 233 377 610 987
public JoniRegexEngine(String regex, int flags) { this.regex = regex; byte[] b = Bytes.toBytes(regex); this.pattern = new Regex(b, 0, b.length, patternToJoniFlags(flags), encoding, Syntax.Java); }
static void Main(string[] args) { var sourceMapFolder = new DirectoryInfo(args[0]); foreach (var sourceMapFile in sourceMapFolder.EnumerateFiles("*.map")) { var sourceMapFilePath = sourceMapFile.FullName; var regex = new Regex(",\\s*[^\\s\\\";]{1,3}?(;|\\\")"); var oldContent = File.ReadAllText(sourceMapFilePath); var newContent = regex.Replace(oldContent, "$1"); File.WriteAllText(sourceMapFilePath, newContent); } }
Regex re = new Regex("^[a-zA-Z0-9][a-zA-Z0-9-]{1,61}[a-zA-Z0-9](?:\\.[a-zA-Z]{1,})+$"); if (!re.IsMatch (domain.Text)) { warningLabel.Text = "Domain format is invalid!"; formError = true; }
string myString = "B12"; Regex rx = new Regex(@"[A-Za-z](\\d+)"); MatchCollection matches = rx.Matches(myString); if (matches.Count > 0) { Match match = matches[0]; // only one match in this case GroupCollection groupCollection = match.Groups; Console.WriteLine("serial " + groupCollection[1].ToString()); }
public JoniRegexEngine(String regex, int flags) { this.regex = regex; byte[] b = Bytes.toBytes(regex); this.pattern = new Regex(b, 0, b.length, patternToJoniFlags(flags), encoding, Syntax.Java); }
private void makeRegexp(ByteList bytes, int start, int len, int flags, Encoding enc) { try { pattern = new Regex(bytes.bytes, start, start + len, flags, enc, Syntax.DEFAULT, this); } catch(Exception e) { rb_reg_raise(bytes.bytes, start, len, e.getMessage(), flags); } }
var reg = new Regex("(\\d+)$"); var matches = reg.Matches("some string 0123"); List<string> found = new List<string>(); if(matches != null) { foreach(Match m in matches) found.Add(m.Groups[1].Value); } //do whatever you want with found
Regex r = new Regex("^data:(.*?);base64,(.*?)$"); Match m = r.Match(fileData); if(m.Success) { string mimeType = m.Groups[1].Value; }
Try this string ss = "<b><i>The tag is about to be removed</i></b>"; Regex regex = new Regex("\\<[^\\>]*\\>"); Response.Write(String.Format("<b>Before:</b>{0}", ss)); // HTML Text Response.Write("<br/>"); ss = regex.Replace(ss, String.Empty); Response.Write(String.Format("<b>After:</b>{0}", ss));// Plain Text as a OUTPUT
string s = "FREQ=WEEKLY;WKST=MO;BYDAY=22TU,-2WE,+223FR"; Regex r = new Regex(@"(?:;BYDAY=|,)([+-]?[0-9]+)([A-Z]{2})"); foreach (Match m in r.Matches(s)) { Console.WriteLine("Interval: {0,5}, Day of Week: {1}", m.Groups[1], m.Groups[2]); }
public Pattern(final String regexText, final String flags) throws JsonQueryException { final int modifiers = parseModifiers(flags) | Option.CAPTURE_GROUP; final byte[] regexBytes = regexText.getBytes(StandardCharsets.UTF_8); this.regex = new Regex(regexBytes, 0, regexBytes.length, modifiers, UTF8Encoding.INSTANCE, Syntax.PerlNG); this.global = isGlobal(flags); this.names = names(regex); }
public Pattern(final String regexText, final String flags) throws JsonQueryException { final int modifiers = parseModifiers(flags) | Option.CAPTURE_GROUP; final byte[] regexBytes = regexText.getBytes(StandardCharsets.UTF_8); this.regex = new Regex(regexBytes, 0, regexBytes.length, modifiers, UTF8Encoding.INSTANCE, Syntax.PerlNG); this.global = isGlobal(flags); this.names = names(regex); }
private static Regex makeRegexp(Ruby runtime, ByteList bytes, RegexpOptions options, Encoding enc) { try { int p = bytes.getBegin(); return new Regex(bytes.getUnsafeBytes(), p, p + bytes.getRealSize(), options.toJoniOptions(), enc, Syntax.DEFAULT, runtime.getRegexpWarnings()); } catch (Exception e) { RegexpSupport.raiseRegexpError19(runtime, bytes, enc, options, e.getMessage()); return null; // not reached } }
private static Regex makeRegexp(Ruby runtime, ByteList bytes, RegexpOptions options, Encoding enc) { try { int p = bytes.getBegin(); return new Regex(bytes.getUnsafeBytes(), p, p + bytes.getRealSize(), options.toJoniOptions(), enc, Syntax.DEFAULT, runtime.getRegexpWarnings()); } catch (Exception e) { RegexpSupport.raiseRegexpError19(runtime, bytes, enc, options, e.getMessage()); return null; // not reached } }