Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Pattern intsOnly = Pattern.compile("\d*");
- Matcher makeMatch = intsOnly.matcher("dadsad14 dssaf jfdkasl;fj");
- makeMatch.find();
- String inputInt = makeMatch.group();
- System.out.println(inputInt);
- "\d+"
- unescaped: ([+-]?d+)([eE][+-]?d+)?
- escaped: ([\+-]?\d+)([eE][\+-]?\d+)?
- unescaped: ([+-]?d(.d*)?|.d+)([eE][+-]?(d(.d*)?|.d+))?
- escaped: ([\+-]?\d(\.\d*)?|\.d+)([eE][\+-]?(\d(\.\d*)?|\.\d+))?
- public T[] GetMatches<T>(string Input, string MatchPattern) where T : IConvertible
- {
- List<T> MatchedValues = new List<T>();
- Regex MatchInt = new Regex(MatchPattern);
- MatchCollection Matches = MatchInt.Matches(Input);
- foreach (Match m in Matches)
- MatchedValues.Add((T)Convert.ChangeType(m.Value, typeof(T)));
- return MatchedValues.ToArray<T>();
- }
- string Test = "22$data44abc";
- string[] Matches = this.GetMatches<string>(Test, "\d+");
Add Comment
Please, Sign In to add comment