示例#1
0
		public  string sub(string str, Filter rf)
		{
			Regsub rs = new Regsub(this, str);
			if (rs.nextMatch() == false)
			{
				return str;
			}
			
			System.Text.StringBuilder sb = new System.Text.StringBuilder();
			do 
			{
				sb.Append(rs.skipped());
				if (rf.filter(rs, sb) == false)
				{
					break;
				}
			}
			while (rs.nextMatch());
			sb.Append(rs.rest());
			return sb.ToString();
		}
示例#2
0
		/// <summary> Matches a string against a regular expression and replaces the first
		/// match with the string generated from the substitution parameter.
		/// 
		/// </summary>
		/// <param name="">str
		/// The string to match against this regular expression.
		/// 
		/// </param>
		/// <param name="">subspec
		/// The substitution parameter, described in <a href=#regsub>
		/// REGULAR EXPRESSION SUBSTITUTION</a>.
		/// 
		/// </param>
		/// <returns>	The string formed by replacing the first match in
		/// <code>str</code> with the string generated from
		/// <code>subspec</code>.  If no matches were found, then
		/// the return value is <code>null</code>.
		/// </returns>
		public  string sub(string str, string subspec)
		{
			Regsub rs = new Regsub(this, str);
			if (rs.nextMatch())
			{
				System.Text.StringBuilder sb = new System.Text.StringBuilder(rs.skipped());
				applySubspec(rs, subspec, sb);
				sb.Append(rs.rest());
				
				return sb.ToString();
			}
			else
			{
				return null;
			}
		}