Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/regex/16.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 用颜色解析VT100文本(对于正则表达式)_Java_Regex_String_Apache Commons_Vt100 - Fatal编程技术网

Java 用颜色解析VT100文本(对于正则表达式)

Java 用颜色解析VT100文本(对于正则表达式),java,regex,string,apache-commons,vt100,Java,Regex,String,Apache Commons,Vt100,我正在使用Apache通过telnet进行连接,并希望将编码更改为纯文本 但是,在尝试处理响应时,会附带Stringresponse。如何删除颜色编码以获得纯文本 我最终得到的片段如下(仅用于说明): 问题是CSI色码会随车而来。如何将字符串编码从VT100转换为VT100 用于说明的Java示例: You say: confusing the hell out of bob. 482 636 [w]Sep 13, 2013 8:13:13 PM telnet.player.RegexWorke

我正在使用Apache通过telnet进行连接,并希望将编码更改为纯文本

但是,在尝试处理响应时,会附带
String
response。如何删除颜色编码以获得纯文本

我最终得到的片段如下(仅用于说明):

问题是CSI色码会随车而来。如何将
字符串
编码从VT100转换为VT100

用于说明的Java示例:

You say: confusing the hell out of bob.
482 636 [w]Sep 13, 2013 8:13:13 PM telnet.player.RegexWorker parseAndUpdatePlayerCharacter
INFO: You say: confusing the hell out of bob.
482 636 [w]
Sep 13, 2013 8:13:13 PM telnet.player.RegexWorker parseAndUpdatePlayerCharacter
INFO: 0mYou
Sep 13, 2013 8:13:13 PM telnet.player.RegexWorker parseAndUpdatePlayerCharacter
INFO: say
package examples;

/* ====================================================================
 * The Apache Software License, Version 1.1
 *
 * Copyright (c) 2001 The Apache Software Foundation.  All rights
 * reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:
 *
 * 1. Redistributions of source code must retain the above copyright
 *    notice, this list of conditions and the following disclaimer.
 *
 * 2. Redistributions in binary form must reproduce the above copyright
 *    notice, this list of conditions and the following disclaimer in
 *    the documentation and/or other materials provided with the
 *    distribution.
 *
 * 3. The end-user documentation included with the redistribution,
 *    if any, must include the following acknowledgment:
 *       "This product includes software developed by the
 *        Apache Software Foundation (http://www.apache.org/)."
 *    Alternately, this acknowledgment may appear in the software itself,
 *    if and wherever such third-party acknowledgments normally appear.
 *
 * 4. The names "Apache" and "Apache Software Foundation" and
 *    "Apache Commons" must not be used to endorse or promote products
 *    derived from this software without prior written permission. For
 *    written permission, please contact apache@apache.org.
 *
 * 5. Products derived from this software may not be called "Apache",
 *    nor may "Apache" appear in their name, without
 *    prior written permission of the Apache Software Foundation.
 *
 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
 * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
 * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
 * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
 * SUCH DAMAGE.
 * ====================================================================
 *
 * This software consists of voluntary contributions made by many
 * individuals on behalf of the Apache Software Foundation.  For more
 * information on the Apache Software Foundation, please see
 * <http://www.apache.org/>.
 */

import java.io.IOException;
import org.apache.commons.net.telnet.TelnetClient;

/***
 * This is an example of a trivial use of the TelnetClient class.
 * It connects to the weather server at the University of Michigan,
 * um-weather.sprl.umich.edu port 3000, and allows the user to interact
 * with the server via standard input.  You could use this example to
 * connect to any telnet server, but it is obviously not general purpose
 * because it reads from standard input a line at a time, making it
 * inconvenient for use with a remote interactive shell.  The TelnetClient
 * class used by itself is mostly intended for automating access to telnet
 * resources rather than interactive use.
 * <p>
 ***/

// This class requires the IOUtil support class!
public final class weatherTelnet
{

    public final static void main(String[] args)
    {
        TelnetClient telnet;

        telnet = new TelnetClient();

        try
        {
            telnet.connect("rainmaker.wunderground.com", 3000);
        }
        catch (IOException e)
        {
            e.printStackTrace();
            System.exit(1);
        }

        IOUtil.readWrite(telnet.getInputStream(), telnet.getOutputStream(),
                         System.in, System.out);

        try
        {
            telnet.disconnect();
        }
        catch (IOException e)
        {
            e.printStackTrace();
            System.exit(1);
        }

        System.exit(0);
    }

}
包示例;
/* ====================================================================
*Apache软件许可证,版本1.1
*
* Copyright(C)2001 Apache软件基金会。所有权利
*保留的。
*
*以源代码和二进制形式重新分发和使用,带或不带
*如果满足以下条件,则允许进行修改
*满足以下条件:
*
* 1. 源代码的重新分发必须保留上述版权
*请注意,此条件列表和以下免责声明。
*
* 2. 以二进制形式重新分发必须复制上述版权
*请注意,此条件列表和中的以下免责声明
*随附的文件和/或其他材料
*分配。
*
* 3. 重新分发中包含的最终用户文档,
*如果有,必须包括以下确认:
*“本产品包括由
*Apache软件基金会(Apache软件基金会)http://www.apache.org/)."
*或者,此确认可能出现在软件本身中,
*在通常出现此类第三方确认的情况下以及在任何地方。
*
* 4. 名称“Apache”和“Apache软件基金会”以及
*“Apache Commons”不得用于支持或推广产品
*未经事先书面许可,从本软件派生。对于
*书面许可,请联系apache@apache.org.
*
* 5. 从该软件派生的产品不能称为“Apache”,
*在他们的名字中也不能出现“Apache”,除非
* Apache软件基金会的事先书面许可。
*
*本软件按“原样”和任何明示或暗示的方式提供
*保证,包括但不限于默示保证
*对适销性和特定用途适用性的评估
*否认。Apache软件基金会或
*其出资人对任何直接、间接、附带,
*特殊、惩戒性或后果性损害(包括但不限于
*仅限于采购替代货物或服务;损失
*使用、数据或利润;或业务中断),无论是何种原因造成的,以及
*关于任何责任理论,无论是在合同中,还是在严格责任中,
*或以任何方式产生的侵权行为(包括疏忽或其他)
*本软件的使用情况,即使被告知
*这样的破坏。
* ====================================================================
*
*该软件由许多人的自愿捐款组成
*代表Apache软件基金会的个人。更多
*关于Apache软件基金会的信息,请参阅
* .
*/
导入java.io.IOException;
导入org.apache.commons.net.telnet.TelnetClient;
/***
*这是一个简单使用TelnetClient类的示例。
*它连接到密歇根大学的天气服务器,
*um-weather.sprl.umich.edu端口3000,并允许用户进行交互
*通过标准输入与服务器连接。您可以使用此示例
*连接到任何telnet服务器,但它显然不是通用的
*因为它每次从标准输入读取一行,使
*与远程交互式外壳一起使用不方便。TelnetClient
*类本身主要用于自动访问telnet
*资源而不是交互使用。
*
***/
//这个类需要IOUtil支持类!
公共末级天气电话网
{
公共最终静态void main(字符串[]args)
{
telnet客户端telnet;
telnet=新的TelnetClient();
尝试
{
telnet.connect(“rainmaker.wunderground.com”,3000);
}
捕获(IOE异常)
{
e、 printStackTrace();
系统出口(1);
}
IOUtil.readWrite(telnet.getInputStream(),telnet.getOutputStream(),
系统输入,系统输出);
尝试
{
telnet.disconnect();
}
捕获(IOE异常)
{
e、 printStackTrace();
系统出口(1);
}
系统出口(0);
}
}
但是,根据您连接到的服务器,响应不会是纯文本的——上面的代码只是为了说明
ApacheTelnet

或者,是否可以通过
TERMINAL\u TYPE
字段将Apache
TelnetClient
实例设置为仅接受纯文本?然而,这个字段是最终的


困难的是在VT100彩色文本上运行正则表达式——如何忽略颜色?或者,只处理纯文本字符串?

虽然不是免费的(如啤酒),但这看起来很有趣:用空字符串替换所有出现的
“\\e\\[[0-9;]*m”
是否还不够?