Changeset 5637 for lang/scala/sandbox
- Timestamp:
- 01/27/08 19:06:40 (5 years ago)
- Files:
-
- 1 modified
Legend:
- Unmodified
- Added
- Removed
-
lang/scala/sandbox/src/jp/ne/cappuccino/keisuken/util/regex/Regex.scala
r5616 r5637 8 8 import java.util.regex._ 9 9 10 /** 11 * Regex library. 12 * @author NISHIMOTO Keisuke. 13 */ 10 14 class Regex(pat: Pattern) { 11 15 def this(regex: String) = this(Pattern.compile(regex)) … … 30 34 matched 31 35 } 36 def first: String = { 37 mat.reset() 38 if(mat.find()) input.substring(mat.start(), mat.end()) else null 39 } 40 def last: String = { 41 var start: Int = 0 42 var end: Int = 0 43 mat.reset() 44 while(mat.find()) {start = mat.start(); end = mat.end()} 45 if(start >= 0 & start != end) input.substring(start, end) else null 46 } 32 47 } 33 48 … … 35 50 def apply(regex: String) = new Regex(regex) 36 51 def apply(regex: String, input: String) = new Regex(regex).matches(input) 52 def quote(input: String): String = Pattern.quote(input) 37 53 } 38 54 … … 47 63 println(str) 48 64 } 65 println(RE.quote("This is a pen.")); 66 println(RE("[A-Za-z]+", "This is a pen.").first); 67 println(RE("[A-Za-z]+", "This is a pen.").last); 49 68 } 50 69 }
![(please configure the [header_logo] section in trac.ini)](/share/chrome/site/your_project_logo.png)